···449449 query = `select count(id) from repos where did = ?`
450450 args = append(args, did)
451451 case models.VanityStatStarCount:
452452- query = `select count(id) from stars where subject_at like 'at://' || ? || '%'`
452452+ query = `select count(s.id) from stars s join repos r on (s.subject_at = r.at_uri or (s.subject_did is not null and s.subject_did = r.repo_did)) where r.did = ?`
453453 args = append(args, did)
454454 case models.VanityStatNone:
455455 return 0, nil
+36-12
appview/db/reference.go
···6060 on r.did = inp.owner_did
6161 and r.name = inp.name
6262 join issues i
6363- on i.repo_at = r.at_uri
6363+ on coalesce(
6464+ nullif(i.repo_did, '') = nullif(r.repo_did, ''),
6565+ i.repo_at = r.at_uri
6666+ )
6467 and i.issue_id = inp.issue_id
6568 left join issue_comments c
6669 on inp.comment_id is not null
···131134 on r.did = inp.owner_did
132135 and r.name = inp.name
133136 join pulls p
134134- on p.repo_at = r.at_uri
137137+ on coalesce(
138138+ nullif(p.repo_did, '') = nullif(r.repo_did, ''),
139139+ p.repo_at = r.at_uri
140140+ )
135141 and p.pull_id = inp.pull_id
136142 left join pull_comments c
137143 on inp.comment_id is not null
138138- and c.repo_at = r.at_uri and c.pull_id = p.pull_id
144144+ and coalesce(
145145+ nullif(c.repo_did, '') = nullif(r.repo_did, ''),
146146+ c.repo_at = r.at_uri
147147+ ) and c.pull_id = p.pull_id
139148 and c.id = inp.comment_id
140149 `,
141150 strings.Join(vals, ","),
···316325 }
317326 rows, err := e.Query(
318327 fmt.Sprintf(
319319- `select r.did, r.name, i.issue_id, i.title, i.open
328328+ `select distinct r.did, r.name, i.issue_id, i.title, i.open
320329 from issues i
321330 join repos r
322322- on r.at_uri = i.repo_at
331331+ on coalesce(
332332+ nullif(i.repo_did, '') = nullif(r.repo_did, ''),
333333+ i.repo_at = r.at_uri
334334+ )
323335 where (i.did, i.rkey) in (%s)`,
324336 strings.Join(vals, ","),
325337 ),
···351363 filter := orm.FilterIn("c.at_uri", aturis)
352364 rows, err := e.Query(
353365 fmt.Sprintf(
354354- `select r.did, r.name, i.issue_id, c.id, i.title, i.open
366366+ `select distinct r.did, r.name, i.issue_id, c.id, i.title, i.open
355367 from issue_comments c
356368 join issues i
357369 on i.at_uri = c.issue_at
358370 join repos r
359359- on r.at_uri = i.repo_at
371371+ on coalesce(
372372+ nullif(i.repo_did, '') = nullif(r.repo_did, ''),
373373+ i.repo_at = r.at_uri
374374+ )
360375 where %s`,
361376 filter.Condition(),
362377 ),
···396411 }
397412 rows, err := e.Query(
398413 fmt.Sprintf(
399399- `select r.did, r.name, p.pull_id, p.title, p.state
414414+ `select distinct r.did, r.name, p.pull_id, p.title, p.state
400415 from pulls p
401416 join repos r
402402- on r.at_uri = p.repo_at
417417+ on coalesce(
418418+ nullif(p.repo_did, '') = nullif(r.repo_did, ''),
419419+ p.repo_at = r.at_uri
420420+ )
403421 where (p.owner_did, p.rkey) in (%s)`,
404422 strings.Join(vals, ","),
405423 ),
···431449 filter := orm.FilterIn("c.comment_at", aturis)
432450 rows, err := e.Query(
433451 fmt.Sprintf(
434434- `select r.did, r.name, p.pull_id, c.id, p.title, p.state
452452+ `select distinct r.did, r.name, p.pull_id, c.id, p.title, p.state
435453 from repos r
436454 join pulls p
437437- on r.at_uri = p.repo_at
455455+ on coalesce(
456456+ nullif(p.repo_did, '') = nullif(r.repo_did, ''),
457457+ p.repo_at = r.at_uri
458458+ )
438459 join pull_comments c
439439- on r.at_uri = c.repo_at and p.pull_id = c.pull_id
460460+ on coalesce(
461461+ nullif(c.repo_did, '') = nullif(r.repo_did, ''),
462462+ c.repo_at = r.at_uri
463463+ ) and p.pull_id = c.pull_id
440464 where %s`,
441465 filter.Condition(),
442466 ),
···77)
8899type Star struct {
1010- Did string
1111- RepoAt syntax.ATURI
1212- Created time.Time
1313- Rkey string
1010+ Did string
1111+ RepoAt syntax.ATURI
1212+ SubjectDid string
1313+ Created time.Time
1414+ Rkey string
1415}
15161617// RepoStar is used for reverse mapping to repos
···30303131// NOTE: this... should not even be here. the entire package will be removed in future refactor
3232func GetBaseRepoPath(r *http.Request, repo *models.Repo) string {
3333+ if repo.RepoDid != "" {
3434+ return repo.RepoDid
3535+ }
3336 var (
3437 user = chi.URLParam(r, "user")
3538 name = chi.URLParam(r, "repo")
···108111 // this is basically a models.Repo
109112 OwnerDid: ownerId.DID.String(),
110113 OwnerHandle: ownerId.Handle.String(),
114114+ RepoDid: repo.RepoDid,
111115 Name: repo.Name,
112116 Rkey: repo.Rkey,
113117 Description: repo.Description,