Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: hide self-referencing backlinks

Signed-off-by: Seongmin Lee <git@boltless.me>

authored by

Seongmin Lee and committed by tangled.org fdb47c29 ff7ddde5

+13 -9
+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 ··· 358 357 on i.at_uri = c.issue_at 359 358 join repos r 360 359 on r.at_uri = i.repo_at 361 - where %s`, 360 + where %s and %s`, 362 361 filter.Condition(), 362 + exclude.Condition(), 363 363 ), 364 - filter.Arg()..., 364 + append(filter.Arg(), exclude.Arg()...)..., 365 365 ) 366 366 if err != nil { 367 367 return nil, err ··· 426 424 return refLinks, nil 427 425 } 428 426 429 - func getPullCommentBacklinks(e Execer, aturis []syntax.ATURI) ([]models.RichReferenceLink, error) { 427 + func getPullCommentBacklinks(e Execer, target syntax.ATURI, aturis []syntax.ATURI) ([]models.RichReferenceLink, error) { 430 428 if len(aturis) == 0 { 431 429 return nil, nil 432 430 } 433 431 filter := orm.FilterIn("c.comment_at", aturis) 432 + exclude := orm.FilterNotEq("p.at_uri", target) 434 433 rows, err := e.Query( 435 434 fmt.Sprintf( 436 435 `select r.did, r.name, p.pull_id, c.id, p.title, p.state ··· 440 437 on r.at_uri = p.repo_at 441 438 join pull_comments c 442 439 on r.at_uri = c.repo_at and p.pull_id = c.pull_id 443 - where %s`, 440 + where %s and %s`, 444 441 filter.Condition(), 442 + exclude.Condition(), 445 443 ), 446 - filter.Arg()..., 444 + append(filter.Arg(), exclude.Arg()...)..., 447 445 ) 448 446 if err != nil { 449 447 return nil, err