Signed-off-by: Seongmin Lee git@boltless.me
+13
-9
Diff
round #0
+13
-9
appview/db/reference.go
+13
-9
appview/db/reference.go
···
253
253
func GetBacklinks(e Execer, target syntax.ATURI) ([]models.RichReferenceLink, error) {
254
254
rows, err := e.Query(
255
255
`select from_at from reference_links
256
-
where to_at = ?`,
256
+
where to_at = ? and from_at <> to_at`,
257
257
target,
258
258
)
259
259
if err != nil {
···
283
283
return nil, fmt.Errorf("get issue backlinks: %w", err)
284
284
}
285
285
backlinks = append(backlinks, ls...)
286
-
ls, err = getIssueCommentBacklinks(e, backlinksMap[tangled.RepoIssueCommentNSID])
286
+
ls, err = getIssueCommentBacklinks(e, target, backlinksMap[tangled.RepoIssueCommentNSID])
287
287
if err != nil {
288
288
return nil, fmt.Errorf("get issue_comment backlinks: %w", err)
289
289
}
···
293
293
return nil, fmt.Errorf("get pull backlinks: %w", err)
294
294
}
295
295
backlinks = append(backlinks, ls...)
296
-
ls, err = getPullCommentBacklinks(e, backlinksMap[tangled.RepoPullCommentNSID])
296
+
ls, err = getPullCommentBacklinks(e, target, backlinksMap[tangled.RepoPullCommentNSID])
297
297
if err != nil {
298
298
return nil, fmt.Errorf("get pull_comment backlinks: %w", err)
299
299
}
···
344
344
return refLinks, nil
345
345
}
346
346
347
-
func getIssueCommentBacklinks(e Execer, aturis []syntax.ATURI) ([]models.RichReferenceLink, error) {
347
+
func getIssueCommentBacklinks(e Execer, target syntax.ATURI, aturis []syntax.ATURI) ([]models.RichReferenceLink, error) {
348
348
if len(aturis) == 0 {
349
349
return nil, nil
350
350
}
351
351
filter := orm.FilterIn("c.at_uri", aturis)
352
+
exclude := orm.FilterNotEq("i.at_uri", target)
352
353
rows, err := e.Query(
353
354
fmt.Sprintf(
354
355
`select r.did, r.name, i.issue_id, c.id, i.title, i.open
···
357
358
on i.at_uri = c.issue_at
358
359
join repos r
359
360
on r.at_uri = i.repo_at
360
-
where %s`,
361
+
where %s and %s`,
361
362
filter.Condition(),
363
+
exclude.Condition(),
362
364
),
363
-
filter.Arg()...,
365
+
append(filter.Arg(), exclude.Arg()...)...,
364
366
)
365
367
if err != nil {
366
368
return nil, err
···
424
426
return refLinks, nil
425
427
}
426
428
427
-
func getPullCommentBacklinks(e Execer, aturis []syntax.ATURI) ([]models.RichReferenceLink, error) {
429
+
func getPullCommentBacklinks(e Execer, target syntax.ATURI, aturis []syntax.ATURI) ([]models.RichReferenceLink, error) {
428
430
if len(aturis) == 0 {
429
431
return nil, nil
430
432
}
431
433
filter := orm.FilterIn("c.comment_at", aturis)
434
+
exclude := orm.FilterNotEq("p.at_uri", target)
432
435
rows, err := e.Query(
433
436
fmt.Sprintf(
434
437
`select r.did, r.name, p.pull_id, c.id, p.title, p.state
···
437
440
on r.at_uri = p.repo_at
438
441
join pull_comments c
439
442
on r.at_uri = c.repo_at and p.pull_id = c.pull_id
440
-
where %s`,
443
+
where %s and %s`,
441
444
filter.Condition(),
445
+
exclude.Condition(),
442
446
),
443
-
filter.Arg()...,
447
+
append(filter.Arg(), exclude.Arg()...)...,
444
448
)
445
449
if err != nil {
446
450
return nil, err
History
1 round
2 comments
boltless.me
submitted
#0
1 commit
expand
collapse
appview: hide self-referencing backlinks
Signed-off-by: Seongmin Lee <git@boltless.me>
1/3 failed, 2/3 success
expand
collapse
no conflicts, ready to merge
fix https://tangled.org/tangled.org/core/issues/336