Lewis: May this revision serve well! lewis@tangled.org
+337
-313
Diff
round #0
+4
-4
appview/db/artifact.go
+4
-4
appview/db/artifact.go
···
16
16
`insert or ignore into artifacts (
17
17
did,
18
18
rkey,
19
-
repo_at,
19
+
repo_did,
20
20
tag,
21
21
created,
22
22
blob_cid,
···
27
27
values (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
28
28
artifact.Did,
29
29
artifact.Rkey,
30
-
artifact.RepoAt,
30
+
artifact.RepoDid,
31
31
artifact.Tag[:],
32
32
artifact.CreatedAt.Format(time.RFC3339),
33
33
artifact.BlobCid.String(),
···
56
56
query := fmt.Sprintf(`select
57
57
did,
58
58
rkey,
59
-
repo_at,
59
+
repo_did,
60
60
tag,
61
61
created,
62
62
blob_cid,
···
82
82
if err := rows.Scan(
83
83
&artifact.Did,
84
84
&artifact.Rkey,
85
-
&artifact.RepoAt,
85
+
&artifact.RepoDid,
86
86
&tag,
87
87
&createdAt,
88
88
&blobCid,
+11
-11
appview/db/collaborators.go
+11
-11
appview/db/collaborators.go
···
11
11
12
12
func AddCollaborator(e Execer, c models.Collaborator) error {
13
13
_, err := e.Exec(
14
-
`insert into collaborators (did, rkey, subject_did, repo_at) values (?, ?, ?, ?);`,
15
-
c.Did, c.Rkey, c.SubjectDid, c.RepoAt,
14
+
`insert into collaborators (did, rkey, subject_did, repo_did) values (?, ?, ?, ?);`,
15
+
c.Did, c.Rkey, c.SubjectDid, string(c.RepoDid),
16
16
)
17
17
return err
18
18
}
···
37
37
}
38
38
39
39
func CollaboratingIn(e Execer, collaborator string) ([]models.Repo, error) {
40
-
rows, err := e.Query(`select repo_at from collaborators where subject_did = ?`, collaborator)
40
+
rows, err := e.Query(`select repo_did from collaborators where subject_did = ?`, collaborator)
41
41
if err != nil {
42
42
return nil, err
43
43
}
44
44
defer rows.Close()
45
45
46
-
var repoAts []string
46
+
var repoDids []string
47
47
for rows.Next() {
48
-
var aturi string
49
-
err := rows.Scan(&aturi)
48
+
var repoDid string
49
+
err := rows.Scan(&repoDid)
50
50
if err != nil {
51
51
return nil, err
52
52
}
53
-
repoAts = append(repoAts, aturi)
53
+
repoDids = append(repoDids, repoDid)
54
54
}
55
55
if err := rows.Err(); err != nil {
56
56
return nil, err
57
57
}
58
-
if repoAts == nil {
58
+
if repoDids == nil {
59
59
return nil, nil
60
60
}
61
61
62
-
return GetRepos(e, orm.FilterIn("at_uri", repoAts))
62
+
return GetRepos(e, orm.FilterIn("repo_did", repoDids))
63
63
}
64
64
65
65
func GetCollaborators(e Execer, filters ...orm.Filter) ([]models.Collaborator, error) {
···
79
79
did,
80
80
rkey,
81
81
subject_did,
82
-
repo_at,
82
+
repo_did,
83
83
created
84
84
from collaborators %s`,
85
85
whereClause,
···
97
97
&collaborator.Did,
98
98
&collaborator.Rkey,
99
99
&collaborator.SubjectDid,
100
-
&collaborator.RepoAt,
100
+
&collaborator.RepoDid,
101
101
&createdAt,
102
102
); err != nil {
103
103
return nil, err
+18
-18
appview/db/issues.go
+18
-18
appview/db/issues.go
···
19
19
func PutIssue(tx *sql.Tx, issue *models.Issue) error {
20
20
// ensure sequence exists
21
21
_, err := tx.Exec(`
22
-
insert or ignore into repo_issue_seqs (repo_at, next_issue_id)
22
+
insert or ignore into repo_issue_seqs (repo_did, next_issue_id)
23
23
values (?, 1)
24
-
`, issue.RepoAt)
24
+
`, issue.RepoDid)
25
25
if err != nil {
26
26
return err
27
27
}
···
57
57
err := tx.QueryRow(`
58
58
update repo_issue_seqs
59
59
set next_issue_id = next_issue_id + 1
60
-
where repo_at = ?
60
+
where repo_did = ?
61
61
returning next_issue_id - 1
62
-
`, issue.RepoAt).Scan(&newIssueId)
62
+
`, issue.RepoDid).Scan(&newIssueId)
63
63
if err != nil {
64
64
return err
65
65
}
66
66
67
67
// insert new issue
68
68
row := tx.QueryRow(`
69
-
insert into issues (repo_at, did, rkey, issue_id, title, body)
69
+
insert into issues (repo_did, did, rkey, issue_id, title, body)
70
70
values (?, ?, ?, ?, ?, ?)
71
71
returning rowid, issue_id
72
-
`, issue.RepoAt, issue.Did, issue.Rkey, newIssueId, issue.Title, issue.Body)
72
+
`, issue.RepoDid, issue.Did, issue.Rkey, newIssueId, issue.Title, issue.Body)
73
73
74
74
err = row.Scan(&issue.Id, &issue.IssueId)
75
75
if err != nil {
···
132
132
id,
133
133
did,
134
134
rkey,
135
-
repo_at,
135
+
repo_did,
136
136
issue_id,
137
137
title,
138
138
body,
···
166
166
&issue.Id,
167
167
&issue.Did,
168
168
&issue.Rkey,
169
-
&issue.RepoAt,
169
+
&issue.RepoDid,
170
170
&issue.IssueId,
171
171
&issue.Title,
172
172
&issue.Body,
···
201
201
}
202
202
203
203
// collect reverse repos
204
-
repoAts := make([]string, 0, len(issueMap)) // or just []string{}
204
+
repoDids := make([]string, 0, len(issueMap))
205
205
for _, issue := range issueMap {
206
-
repoAts = append(repoAts, string(issue.RepoAt))
206
+
repoDids = append(repoDids, string(issue.RepoDid))
207
207
}
208
208
209
-
repos, err := GetRepos(e, orm.FilterIn("at_uri", repoAts))
209
+
repos, err := GetRepos(e, orm.FilterIn("repo_did", repoDids))
210
210
if err != nil {
211
211
return nil, fmt.Errorf("failed to build repo mappings: %w", err)
212
212
}
213
213
214
214
repoMap := make(map[string]*models.Repo)
215
215
for i := range repos {
216
-
repoMap[string(repos[i].RepoAt())] = &repos[i]
216
+
repoMap[repos[i].RepoDid] = &repos[i]
217
217
}
218
218
219
219
for issueAt, i := range issueMap {
220
-
if r, ok := repoMap[string(i.RepoAt)]; ok {
220
+
if r, ok := repoMap[string(i.RepoDid)]; ok {
221
221
i.Repo = r
222
222
} else {
223
223
// do not show up the issue if the repo is deleted
···
274
274
return issues, nil
275
275
}
276
276
277
-
func GetIssue(e Execer, repoAt syntax.ATURI, issueId int) (*models.Issue, error) {
277
+
func GetIssue(e Execer, repoDid string, issueId int) (*models.Issue, error) {
278
278
issues, err := GetIssuesPaginated(
279
279
e,
280
280
pagination.Page{},
281
-
orm.FilterEq("repo_at", repoAt),
281
+
orm.FilterEq("repo_did", repoDid),
282
282
orm.FilterEq("issue_id", issueId),
283
283
)
284
284
if err != nil {
···
530
530
return err
531
531
}
532
532
533
-
func GetIssueCount(e Execer, repoAt syntax.ATURI) (models.IssueCount, error) {
533
+
func GetIssueCount(e Execer, repoDid string) (models.IssueCount, error) {
534
534
row := e.QueryRow(`
535
535
select
536
536
count(case when open = 1 then 1 end) as open_count,
537
537
count(case when open = 0 then 1 end) as closed_count
538
538
from issues
539
-
where repo_at = ?`,
540
-
repoAt,
539
+
where repo_did = ?`,
540
+
repoDid,
541
541
)
542
542
543
543
var count models.IssueCount
+6
-6
appview/db/language.go
+6
-6
appview/db/language.go
···
24
24
}
25
25
26
26
query := fmt.Sprintf(
27
-
`select id, repo_at, ref, is_default_ref, language, bytes from repo_languages %s`,
27
+
`select id, repo_did, ref, is_default_ref, language, bytes from repo_languages %s`,
28
28
whereClause,
29
29
)
30
30
rows, err := e.Query(query, args...)
···
40
40
41
41
err := rows.Scan(
42
42
&rl.Id,
43
-
&rl.RepoAt,
43
+
&rl.RepoDid,
44
44
&rl.Ref,
45
45
&isDefaultRef,
46
46
&rl.Language,
···
65
65
66
66
func InsertRepoLanguages(e Execer, langs []models.RepoLanguage) error {
67
67
stmt, err := e.Prepare(
68
-
"insert or replace into repo_languages (repo_at, ref, is_default_ref, language, bytes) values (?, ?, ?, ?, ?)",
68
+
"insert or replace into repo_languages (repo_did, ref, is_default_ref, language, bytes) values (?, ?, ?, ?, ?)",
69
69
)
70
70
if err != nil {
71
71
return err
···
77
77
isDefaultRef = 1
78
78
}
79
79
80
-
_, err := stmt.Exec(l.RepoAt, l.Ref, isDefaultRef, l.Language, l.Bytes)
80
+
_, err := stmt.Exec(l.RepoDid, l.Ref, isDefaultRef, l.Language, l.Bytes)
81
81
if err != nil {
82
82
return err
83
83
}
···
105
105
return err
106
106
}
107
107
108
-
func UpdateRepoLanguages(tx *sql.Tx, repoAt syntax.ATURI, ref string, langs []models.RepoLanguage) error {
108
+
func UpdateRepoLanguages(tx *sql.Tx, repoDid syntax.DID, ref string, langs []models.RepoLanguage) error {
109
109
err := DeleteRepoLanguages(
110
110
tx,
111
-
orm.FilterEq("repo_at", repoAt),
111
+
orm.FilterEq("repo_did", repoDid),
112
112
orm.FilterEq("ref", ref),
113
113
)
114
114
if err != nil {
+1
-1
appview/db/profile.go
+1
-1
appview/db/profile.go
···
489
489
query = `select count(id) from repos where did = ?`
490
490
args = append(args, did)
491
491
case models.VanityStatStarCount:
492
-
query = `select count(id) from stars where subject_at like 'at://' || ? || '%'`
492
+
query = `select count(s.id) from stars s join repos r on s.subject = r.repo_did where s.subject_type = 'repo' and r.did = ?`
493
493
args = append(args, did)
494
494
case models.VanityStatNone:
495
495
return 0, nil
+56
-57
appview/db/pulls.go
+56
-57
appview/db/pulls.go
···
30
30
if existing.Branch != new.Branch {
31
31
return false
32
32
}
33
-
if existing.RepoAt == nil && new.RepoAt == nil {
33
+
if existing.RepoDid == nil && new.RepoDid == nil {
34
34
return true
35
35
}
36
-
if existing.RepoAt == nil || new.RepoAt == nil {
36
+
if existing.RepoDid == nil || new.RepoDid == nil {
37
37
return false
38
38
}
39
-
return *existing.RepoAt == *new.RepoAt
39
+
return *existing.RepoDid == *new.RepoDid
40
40
}
41
41
42
42
func compareSubmissions(existing, new []*models.PullSubmission) bool {
···
60
60
func PutPull(tx *sql.Tx, pull *models.Pull) error {
61
61
// ensure sequence exists
62
62
_, err := tx.Exec(`
63
-
insert or ignore into repo_pull_seqs (repo_at, next_pull_id)
63
+
insert or ignore into repo_pull_seqs (repo_did, next_pull_id)
64
64
values (?, 1)
65
-
`, pull.RepoAt)
65
+
`, pull.RepoDid)
66
66
if err != nil {
67
67
return err
68
68
}
···
94
94
if existingPull.Title == pull.Title &&
95
95
existingPull.Body == pull.Body &&
96
96
existingPull.TargetBranch == pull.TargetBranch &&
97
-
existingPull.RepoAt == pull.RepoAt &&
97
+
existingPull.RepoDid == pull.RepoDid &&
98
98
dependentOnEqual &&
99
99
pullSourceEqual &&
100
100
submissionsEqual {
···
119
119
120
120
func createNewPull(tx *sql.Tx, pull *models.Pull) error {
121
121
_, err := tx.Exec(`
122
-
insert or ignore into repo_pull_seqs (repo_at, next_pull_id)
122
+
insert or ignore into repo_pull_seqs (repo_did, next_pull_id)
123
123
values (?, 1)
124
-
`, pull.RepoAt)
124
+
`, pull.RepoDid)
125
125
if err != nil {
126
126
return err
127
127
}
···
130
130
err = tx.QueryRow(`
131
131
update repo_pull_seqs
132
132
set next_pull_id = next_pull_id + 1
133
-
where repo_at = ?
133
+
where repo_did = ?
134
134
returning next_pull_id - 1
135
-
`, pull.RepoAt).Scan(&nextId)
135
+
`, pull.RepoDid).Scan(&nextId)
136
136
if err != nil {
137
137
return err
138
138
}
···
140
140
pull.PullId = nextId
141
141
pull.State = models.PullOpen
142
142
143
-
var sourceBranch, sourceRepoAt *string
143
+
var sourceBranch, sourceRepoDid *string
144
144
if pull.PullSource != nil {
145
145
sourceBranch = &pull.PullSource.Branch
146
-
if pull.PullSource.RepoAt != nil {
147
-
x := pull.PullSource.RepoAt.String()
148
-
sourceRepoAt = &x
146
+
if pull.PullSource.RepoDid != nil {
147
+
x := string(*pull.PullSource.RepoDid)
148
+
sourceRepoDid = &x
149
149
}
150
150
}
151
151
152
152
result, err := tx.Exec(
153
153
`
154
154
insert into pulls (
155
-
repo_at,
155
+
repo_did,
156
156
owner_did,
157
157
pull_id,
158
158
title,
···
162
162
state,
163
163
dependent_on,
164
164
source_branch,
165
-
source_repo_at
165
+
source_repo_did
166
166
)
167
167
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
168
-
pull.RepoAt,
168
+
pull.RepoDid,
169
169
pull.OwnerDid,
170
170
pull.PullId,
171
171
pull.Title,
···
175
175
pull.State,
176
176
pull.DependentOn,
177
177
sourceBranch,
178
-
sourceRepoAt,
178
+
sourceRepoDid,
179
179
)
180
180
if err != nil {
181
181
return err
···
224
224
}
225
225
226
226
func updatePull(tx *sql.Tx, pull *models.Pull, existingPull *models.Pull) error {
227
-
var sourceBranch, sourceRepoAt *string
227
+
var sourceBranch, sourceRepoDid *string
228
228
if pull.PullSource != nil {
229
229
sourceBranch = &pull.PullSource.Branch
230
-
if pull.PullSource.RepoAt != nil {
231
-
x := pull.PullSource.RepoAt.String()
232
-
sourceRepoAt = &x
230
+
if pull.PullSource.RepoDid != nil {
231
+
x := string(*pull.PullSource.RepoDid)
232
+
sourceRepoDid = &x
233
233
}
234
234
}
235
235
···
240
240
target_branch = ?,
241
241
dependent_on = ?,
242
242
source_branch = ?,
243
-
source_repo_at = ?
243
+
source_repo_did = ?
244
244
where owner_did = ? and rkey = ?
245
-
`, pull.Title, pull.Body, pull.TargetBranch, pull.DependentOn, sourceBranch, sourceRepoAt, pull.OwnerDid, pull.Rkey)
245
+
`, pull.Title, pull.Body, pull.TargetBranch, pull.DependentOn, sourceBranch, sourceRepoDid, pull.OwnerDid, pull.Rkey)
246
246
if err != nil {
247
247
return err
248
248
}
···
283
283
return nil
284
284
}
285
285
286
-
func NextPullId(e Execer, repoAt syntax.ATURI) (int, error) {
286
+
func NextPullId(e Execer, repoDid string) (int, error) {
287
287
var pullId int
288
-
err := e.QueryRow(`select next_pull_id from repo_pull_seqs where repo_at = ?`, repoAt).Scan(&pullId)
288
+
err := e.QueryRow(`select next_pull_id from repo_pull_seqs where repo_did = ?`, repoDid).Scan(&pullId)
289
289
return pullId - 1, err
290
290
}
291
291
···
316
316
select
317
317
id,
318
318
owner_did,
319
-
repo_at,
319
+
repo_did,
320
320
pull_id,
321
321
created,
322
322
title,
···
325
325
body,
326
326
rkey,
327
327
source_branch,
328
-
source_repo_at,
328
+
source_repo_did,
329
329
dependent_on
330
330
from
331
331
pulls
···
344
344
for rows.Next() {
345
345
var pull models.Pull
346
346
var createdAt string
347
-
var sourceBranch, sourceRepoAt, dependentOn sql.NullString
347
+
var sourceBranch, sourceRepoDid, dependentOn sql.NullString
348
348
err := rows.Scan(
349
349
&pull.ID,
350
350
&pull.OwnerDid,
351
-
&pull.RepoAt,
351
+
&pull.RepoDid,
352
352
&pull.PullId,
353
353
&createdAt,
354
354
&pull.Title,
···
357
357
&pull.Body,
358
358
&pull.Rkey,
359
359
&sourceBranch,
360
-
&sourceRepoAt,
360
+
&sourceRepoDid,
361
361
&dependentOn,
362
362
)
363
363
if err != nil {
···
374
374
pull.PullSource = &models.PullSource{
375
375
Branch: sourceBranch.String,
376
376
}
377
-
if sourceRepoAt.Valid {
378
-
sourceRepoAtParsed, err := syntax.ParseATURI(sourceRepoAt.String)
377
+
if sourceRepoDid.Valid {
378
+
sourceRepoDidParsed, err := syntax.ParseDID(sourceRepoDid.String)
379
379
if err != nil {
380
380
return nil, err
381
381
}
382
-
pull.PullSource.RepoAt = &sourceRepoAtParsed
382
+
pull.PullSource.RepoDid = &sourceRepoDidParsed
383
383
}
384
384
}
385
385
···
417
417
}
418
418
}
419
419
420
-
// build up reverse mappings: p.Repo and p.PullSource
421
-
var repoAts []syntax.ATURI
420
+
// build up reverse mappings: p.Repo and p.PullSource.Repo
421
+
var repoDids []syntax.DID
422
422
for _, p := range pulls {
423
-
repoAts = append(repoAts, p.RepoAt)
424
-
if p.PullSource != nil && p.PullSource.RepoAt != nil {
425
-
repoAts = append(repoAts, *p.PullSource.RepoAt)
423
+
repoDids = append(repoDids, p.RepoDid)
424
+
if p.PullSource != nil && p.PullSource.RepoDid != nil {
425
+
repoDids = append(repoDids, *p.PullSource.RepoDid)
426
426
}
427
427
}
428
428
429
-
repos, err := GetRepos(e, orm.FilterIn("at_uri", repoAts))
429
+
repos, err := GetRepos(e, orm.FilterIn("repo_did", repoDids))
430
430
if err != nil && !errors.Is(err, sql.ErrNoRows) {
431
-
return nil, fmt.Errorf("failed to get source repos: %w", err)
431
+
return nil, fmt.Errorf("failed to get repos: %w", err)
432
432
}
433
433
434
-
repoMap := make(map[syntax.ATURI]*models.Repo)
434
+
repoMap := make(map[syntax.DID]*models.Repo)
435
435
for _, r := range repos {
436
-
repoMap[r.RepoAt()] = &r
436
+
repoMap[syntax.DID(r.RepoDid)] = &r
437
437
}
438
438
439
439
for _, p := range pulls {
440
-
if repo, ok := repoMap[p.RepoAt]; ok {
440
+
if repo, ok := repoMap[p.RepoDid]; ok {
441
441
p.Repo = repo
442
442
}
443
-
444
-
if p.PullSource != nil && p.PullSource.RepoAt != nil {
445
-
if sourceRepo, ok := repoMap[*p.PullSource.RepoAt]; ok {
443
+
if p.PullSource != nil && p.PullSource.RepoDid != nil {
444
+
if sourceRepo, ok := repoMap[*p.PullSource.RepoDid]; ok {
446
445
p.PullSource.Repo = sourceRepo
447
446
}
448
447
}
···
625
624
id,
626
625
pull_id,
627
626
submission_id,
628
-
repo_at,
627
+
repo_did,
629
628
owner_did,
630
629
comment_at,
631
630
body,
···
651
650
&comment.ID,
652
651
&comment.PullId,
653
652
&comment.SubmissionId,
654
-
&comment.RepoAt,
653
+
&comment.RepoDid,
655
654
&comment.OwnerDid,
656
655
&comment.CommentAt,
657
656
&comment.Body,
···
705
704
rows, err := e.Query(`
706
705
select
707
706
p.owner_did,
708
-
p.repo_at,
707
+
p.repo_did,
709
708
p.pull_id,
710
709
p.created,
711
710
p.title,
···
718
717
from
719
718
pulls p
720
719
join
721
-
repos r on p.repo_at = r.at_uri
720
+
repos r on p.repo_did = r.repo_did
722
721
where
723
722
p.owner_did = ? and p.created >= date ('now', ?)
724
723
order by
···
734
733
var pullCreatedAt, repoCreatedAt string
735
734
err := rows.Scan(
736
735
&pull.OwnerDid,
737
-
&pull.RepoAt,
736
+
&pull.RepoDid,
738
737
&pull.PullId,
739
738
&pullCreatedAt,
740
739
&pull.Title,
···
774
773
}
775
774
776
775
func NewPullComment(tx *sql.Tx, comment *models.PullComment) (int64, error) {
777
-
query := `insert into pull_comments (owner_did, repo_at, submission_id, comment_at, pull_id, body) values (?, ?, ?, ?, ?, ?)`
776
+
query := `insert into pull_comments (owner_did, repo_did, submission_id, comment_at, pull_id, body) values (?, ?, ?, ?, ?, ?)`
778
777
res, err := tx.Exec(
779
778
query,
780
779
comment.OwnerDid,
781
-
comment.RepoAt,
780
+
comment.RepoDid,
782
781
comment.SubmissionId,
783
782
comment.CommentAt,
784
783
comment.PullId,
···
888
887
return err
889
888
}
890
889
891
-
func GetPullCount(e Execer, repoAt syntax.ATURI) (models.PullCount, error) {
890
+
func GetPullCount(e Execer, repoDid string) (models.PullCount, error) {
892
891
row := e.QueryRow(`
893
892
select
894
893
count(case when state = ? then 1 end) as open_count,
···
896
895
count(case when state = ? then 1 end) as closed_count,
897
896
count(case when state = ? then 1 end) as deleted_count
898
897
from pulls
899
-
where repo_at = ?`,
898
+
where repo_did = ?`,
900
899
models.PullOpen,
901
900
models.PullMerged,
902
901
models.PullClosed,
903
902
models.PullAbandoned,
904
-
repoAt,
903
+
repoDid,
905
904
)
906
905
907
906
var count models.PullCount
+8
-8
appview/db/reference.go
+8
-8
appview/db/reference.go
···
60
60
on r.did = inp.owner_did
61
61
and r.name = inp.name
62
62
join issues i
63
-
on i.repo_at = r.at_uri
63
+
on i.repo_did = r.repo_did
64
64
and i.issue_id = inp.issue_id
65
65
left join issue_comments c
66
66
on inp.comment_id is not null
···
131
131
on r.did = inp.owner_did
132
132
and r.name = inp.name
133
133
join pulls p
134
-
on p.repo_at = r.at_uri
134
+
on p.repo_did = r.repo_did
135
135
and p.pull_id = inp.pull_id
136
136
left join pull_comments c
137
137
on inp.comment_id is not null
138
-
and c.repo_at = r.at_uri and c.pull_id = p.pull_id
138
+
and c.repo_did = p.repo_did and c.pull_id = p.pull_id
139
139
and c.id = inp.comment_id
140
140
`,
141
141
strings.Join(vals, ","),
···
319
319
`select r.did, r.name, i.issue_id, i.title, i.open
320
320
from issues i
321
321
join repos r
322
-
on r.at_uri = i.repo_at
322
+
on r.repo_did = i.repo_did
323
323
where (i.did, i.rkey) in (%s)`,
324
324
strings.Join(vals, ","),
325
325
),
···
357
357
join issues i
358
358
on i.at_uri = c.issue_at
359
359
join repos r
360
-
on r.at_uri = i.repo_at
360
+
on r.repo_did = i.repo_did
361
361
where %s and %s`,
362
362
filter.Condition(),
363
363
exclude.Condition(),
···
401
401
`select r.did, r.name, p.pull_id, p.title, p.state
402
402
from pulls p
403
403
join repos r
404
-
on r.at_uri = p.repo_at
404
+
on r.repo_did = p.repo_did
405
405
where (p.owner_did, p.rkey) in (%s)`,
406
406
strings.Join(vals, ","),
407
407
),
···
437
437
`select r.did, r.name, p.pull_id, c.id, p.title, p.state
438
438
from repos r
439
439
join pulls p
440
-
on r.at_uri = p.repo_at
440
+
on r.repo_did = p.repo_did
441
441
join pull_comments c
442
-
on r.at_uri = c.repo_at and p.pull_id = c.pull_id
442
+
on p.repo_did = c.repo_did and p.pull_id = c.pull_id
443
443
where %s and %s`,
444
444
filter.Condition(),
445
445
exclude.Condition(),
+67
-68
appview/db/repos.go
+67
-68
appview/db/repos.go
···
64
64
}
65
65
defer rows.Close()
66
66
67
-
repoMap := make(map[syntax.ATURI]*models.Repo)
67
+
repoMap := make(map[string]*models.Repo)
68
68
for rows.Next() {
69
69
var repo models.Repo
70
70
var createdAt string
···
114
114
}
115
115
116
116
repo.RepoStats = &models.RepoStats{}
117
-
repoMap[repo.RepoAt()] = &repo
117
+
repoMap[repo.RepoDid] = &repo
118
118
}
119
119
120
120
if err = rows.Err(); err != nil {
···
131
131
args = make([]any, len(repoMap))
132
132
i := 0
133
133
for _, r := range repoMap {
134
-
args[i] = r.RepoAt()
134
+
args[i] = r.RepoDid
135
135
i++
136
136
}
137
137
138
138
// get labels for all repos
139
139
labelsQuery := fmt.Sprintf(
140
-
`select repo_at, label_at from repo_labels where repo_at in (%s)`,
140
+
`select repo_did, label_at from repo_labels where repo_did in (%s)`,
141
141
inClause,
142
142
)
143
143
···
148
148
defer rows.Close()
149
149
150
150
for rows.Next() {
151
-
var repoat, labelat string
152
-
if err := rows.Scan(&repoat, &labelat); err != nil {
151
+
var repoDid, labelat string
152
+
if err := rows.Scan(&repoDid, &labelat); err != nil {
153
153
continue
154
154
}
155
-
if r, ok := repoMap[syntax.ATURI(repoat)]; ok {
155
+
if r, ok := repoMap[repoDid]; ok {
156
156
r.Labels = append(r.Labels, labelat)
157
157
}
158
158
}
159
159
160
160
// get primary language for all repos
161
161
languageQuery := fmt.Sprintf(`
162
-
select repo_at, language
162
+
select repo_did, language
163
163
from (
164
164
select
165
-
repo_at, language,
165
+
repo_did, language,
166
166
row_number() over (
167
-
partition by repo_at
167
+
partition by repo_did
168
168
order by bytes desc
169
169
) as rn
170
170
from repo_languages
171
-
where repo_at in (%s)
171
+
where repo_did in (%s)
172
172
and is_default_ref = 1
173
173
and language <> ''
174
174
)
···
182
182
defer rows.Close()
183
183
184
184
for rows.Next() {
185
-
var repoat, lang string
186
-
if err := rows.Scan(&repoat, &lang); err != nil {
185
+
var repoDid, lang string
186
+
if err := rows.Scan(&repoDid, &lang); err != nil {
187
187
log.Println("err", "err", err)
188
188
continue
189
189
}
190
-
if r, ok := repoMap[syntax.ATURI(repoat)]; ok {
190
+
if r, ok := repoMap[repoDid]; ok {
191
191
r.RepoStats.Language = lang
192
192
}
193
193
}
···
197
197
198
198
// get star counts
199
199
starCountQuery := fmt.Sprintf(
200
-
`select subject_at, count(1) from stars where subject_at in (%s) group by subject_at`,
200
+
`select subject, count(1) from stars where subject_type = 'repo' and subject in (%s) group by subject`,
201
201
inClause,
202
202
)
203
203
···
208
208
defer rows.Close()
209
209
210
210
for rows.Next() {
211
-
var repoat string
211
+
var repoDid string
212
212
var count int
213
-
if err := rows.Scan(&repoat, &count); err != nil {
213
+
if err := rows.Scan(&repoDid, &count); err != nil {
214
214
log.Println("err", "err", err)
215
215
continue
216
216
}
217
-
if r, ok := repoMap[syntax.ATURI(repoat)]; ok {
217
+
if r, ok := repoMap[repoDid]; ok {
218
218
r.RepoStats.StarCount = count
219
219
}
220
220
}
···
225
225
// get issue counts
226
226
issueCountQuery := fmt.Sprintf(`
227
227
select
228
-
repo_at,
228
+
repo_did,
229
229
count(case when open = 1 then 1 end) as open_count,
230
230
count(case when open = 0 then 1 end) as closed_count
231
231
from issues
232
-
where repo_at in (%s)
233
-
group by repo_at
232
+
where repo_did in (%s)
233
+
group by repo_did
234
234
`, inClause)
235
235
236
236
rows, err = e.Query(issueCountQuery, args...)
···
240
240
defer rows.Close()
241
241
242
242
for rows.Next() {
243
-
var repoat string
243
+
var repoDid string
244
244
var open, closed int
245
-
if err := rows.Scan(&repoat, &open, &closed); err != nil {
245
+
if err := rows.Scan(&repoDid, &open, &closed); err != nil {
246
246
log.Println("err", "err", err)
247
247
continue
248
248
}
249
-
if r, ok := repoMap[syntax.ATURI(repoat)]; ok {
249
+
if r, ok := repoMap[repoDid]; ok {
250
250
r.RepoStats.IssueCount.Open = open
251
251
r.RepoStats.IssueCount.Closed = closed
252
252
}
···
258
258
// get pull counts
259
259
pullCountQuery := fmt.Sprintf(`
260
260
select
261
-
repo_at,
261
+
repo_did,
262
262
count(case when state = ? then 1 end) as open_count,
263
263
count(case when state = ? then 1 end) as merged_count,
264
264
count(case when state = ? then 1 end) as closed_count,
265
265
count(case when state = ? then 1 end) as deleted_count
266
266
from pulls
267
-
where repo_at in (%s)
268
-
group by repo_at
267
+
where repo_did in (%s)
268
+
group by repo_did
269
269
`, inClause)
270
270
271
271
pullArgs := append([]any{
···
282
282
defer rows.Close()
283
283
284
284
for rows.Next() {
285
-
var repoat string
285
+
var repoDid string
286
286
var open, merged, closed, deleted int
287
-
if err := rows.Scan(&repoat, &open, &merged, &closed, &deleted); err != nil {
287
+
if err := rows.Scan(&repoDid, &open, &merged, &closed, &deleted); err != nil {
288
288
log.Println("err", "err", err)
289
289
continue
290
290
}
291
-
if r, ok := repoMap[syntax.ATURI(repoat)]; ok {
291
+
if r, ok := repoMap[repoDid]; ok {
292
292
r.RepoStats.PullCount.Open = open
293
293
r.RepoStats.PullCount.Merged = merged
294
294
r.RepoStats.PullCount.Closed = closed
···
404
404
}
405
405
_, err := tx.Exec(
406
406
`update repos
407
-
set knot = ?, description = ?, website = ?, topics = ?, repo_did = coalesce(?, repo_did)
407
+
set name = ?, knot = ?, description = ?, website = ?, topics = ?, repo_did = coalesce(?, repo_did)
408
408
where did = ? and rkey = ?
409
409
`,
410
-
repo.Knot, repo.Description, repo.Website, repo.TopicStr(), repoDid, repo.Did, repo.Rkey,
410
+
repo.Name, repo.Knot, repo.Description, repo.Website, repo.TopicStr(), repoDid, repo.Did, repo.Rkey,
411
411
)
412
412
return err
413
413
}
···
435
435
436
436
for _, dl := range repo.Labels {
437
437
if err := SubscribeLabel(tx, &models.RepoLabel{
438
-
RepoAt: repo.RepoAt(),
438
+
RepoDid: syntax.DID(repo.RepoDid),
439
439
LabelAt: syntax.ATURI(dl),
440
440
}); err != nil {
441
441
return fmt.Errorf("failed to subscribe to label: %w", err)
···
445
445
return nil
446
446
}
447
447
448
-
func RemoveRepo(e Execer, did, name string) error {
449
-
_, err := e.Exec(`delete from repos where did = ? and name = ?`, did, name)
448
+
func RemoveRepo(e Execer, did, rkey string) error {
449
+
_, err := e.Exec(`delete from repos where did = ? and rkey = ?`, did, rkey)
450
450
return err
451
451
}
452
452
453
-
func GetRepoSource(e Execer, repoAt syntax.ATURI) (string, error) {
453
+
func GetRepoSource(e Execer, repoDid string) (string, error) {
454
454
var nullableSource sql.NullString
455
-
err := e.QueryRow(`select source from repos where at_uri = ?`, repoAt).Scan(&nullableSource)
455
+
err := e.QueryRow(`select source from repos where repo_did = ?`, repoDid).Scan(&nullableSource)
456
456
if err != nil {
457
457
return "", err
458
458
}
459
459
return nullableSource.String, nil
460
460
}
461
461
462
-
func GetRepoSourceRepo(e Execer, repoAt syntax.ATURI) (*models.Repo, error) {
463
-
source, err := GetRepoSource(e, repoAt)
462
+
func GetRepoSourceRepo(e Execer, repoDid string) (*models.Repo, error) {
463
+
source, err := GetRepoSource(e, repoDid)
464
464
if source == "" || errors.Is(err, sql.ErrNoRows) {
465
465
return nil, nil
466
466
}
···
479
479
rows, err := e.Query(
480
480
`select distinct r.id, r.did, r.name, r.knot, r.rkey, r.description, r.website, r.created, r.source, r.repo_did
481
481
from repos r
482
-
left join collaborators c on r.at_uri = c.repo_at
482
+
left join collaborators c on r.repo_did = c.repo_did
483
483
where (r.did = ? or c.subject_did = ?)
484
484
and r.source is not null
485
485
and r.source != ''
···
535
535
return repos, nil
536
536
}
537
537
538
-
func GetForkByDid(e Execer, did string, name string) (*models.Repo, error) {
538
+
func GetForkByDid(e Execer, did string, rkey string) (*models.Repo, error) {
539
539
var repo models.Repo
540
540
var createdAt string
541
541
var nullableDescription sql.NullString
···
547
547
row := e.QueryRow(
548
548
`select id, did, name, knot, rkey, description, website, topics, created, source, repo_did
549
549
from repos
550
-
where did = ? and name = ? and source is not null and source != ''`,
551
-
did, name,
550
+
where did = ? and rkey = ? and source is not null and source != ''`,
551
+
did, rkey,
552
552
)
553
553
554
554
err := row.Scan(&repo.Id, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &nullableWebsite, &nullableTopicStr, &createdAt, &nullableSource, &nullableRepoDid)
···
595
595
table string
596
596
nsid string
597
597
fkCol string
598
+
fkVal string
598
599
}
599
600
sources := []record{
600
-
{"did", "repos", "sh.tangled.repo", "at_uri"},
601
-
{"did", "issues", "sh.tangled.repo.issue", "repo_at"},
602
-
{"owner_did", "pulls", "sh.tangled.repo.pull", "repo_at"},
603
-
{"did", "collaborators", "sh.tangled.repo.collaborator", "repo_at"},
604
-
{"did", "artifacts", "sh.tangled.repo.artifact", "repo_at"},
605
-
{"did", "stars", "sh.tangled.feed.star", "subject_at"},
601
+
{"did", "repos", "sh.tangled.repo", "at_uri", repoAtUri},
602
+
{"did", "issues", "sh.tangled.repo.issue", "repo_did", repoDid},
603
+
{"owner_did", "pulls", "sh.tangled.repo.pull", "repo_did", repoDid},
604
+
{"did", "collaborators", "sh.tangled.repo.collaborator", "repo_did", repoDid},
605
+
{"did", "artifacts", "sh.tangled.repo.artifact", "repo_did", repoDid},
606
+
{"did", "stars", "sh.tangled.feed.star", "subject", repoDid},
606
607
}
607
608
608
609
for _, src := range sources {
609
610
rows, err := tx.Query(
610
611
fmt.Sprintf(`SELECT %s, rkey FROM %s WHERE %s = ?`, src.userDidCol, src.table, src.fkCol),
611
-
repoAtUri,
612
+
src.fkVal,
612
613
)
613
614
if err != nil {
614
615
return fmt.Errorf("query %s for pds rewrites: %w", src.table, err)
···
629
630
}
630
631
631
632
for _, p := range pairs {
632
-
if err := EnqueuePdsRewrite(tx, p.did, repoDid, src.nsid, p.rkey, repoAtUri); err != nil {
633
+
if err := EnqueuePdsRewrite(tx, p.did, repoDid, src.nsid, p.rkey); err != nil {
633
634
return fmt.Errorf("enqueue pds rewrite for %s/%s: %w", src.table, p.rkey, err)
634
635
}
635
636
}
···
657
658
}
658
659
659
660
for _, d := range profileDids {
660
-
if err := EnqueuePdsRewrite(tx, d, repoDid, "sh.tangled.actor.profile", "self", repoAtUri); err != nil {
661
+
if err := EnqueuePdsRewrite(tx, d, repoDid, "sh.tangled.actor.profile", "self"); err != nil {
661
662
return fmt.Errorf("enqueue pds rewrite for profile/%s: %w", d, err)
662
663
}
663
664
}
···
670
671
RepoDid string
671
672
RecordNsid string
672
673
RecordRkey string
673
-
OldRepoAt string
674
674
}
675
675
676
676
func GetPendingPdsRewrites(e Execer, userDid string) ([]PdsRewrite, error) {
677
677
rows, err := e.Query(
678
-
`SELECT id, repo_did, record_nsid, record_rkey, old_repo_at
678
+
`SELECT id, repo_did, record_nsid, record_rkey
679
679
FROM pds_rewrite_status
680
680
WHERE user_did = ? AND status = 'pending'`,
681
681
userDid,
···
688
688
var rewrites []PdsRewrite
689
689
for rows.Next() {
690
690
var r PdsRewrite
691
-
if err := rows.Scan(&r.Id, &r.RepoDid, &r.RecordNsid, &r.RecordRkey, &r.OldRepoAt); err != nil {
691
+
if err := rows.Scan(&r.Id, &r.RepoDid, &r.RecordNsid, &r.RecordRkey); err != nil {
692
692
return nil, err
693
693
}
694
694
rewrites = append(rewrites, r)
···
704
704
return err
705
705
}
706
706
707
-
func EnqueuePdsRewrite(e Execer, userDid, repoDid, recordNsid, recordRkey, oldRepoAt string) error {
707
+
func EnqueuePdsRewrite(e Execer, userDid, repoDid, recordNsid, recordRkey string) error {
708
708
_, err := e.Exec(
709
709
`INSERT INTO pds_rewrite_status
710
-
(user_did, repo_did, record_nsid, record_rkey, old_repo_at, status)
711
-
VALUES (?, ?, ?, ?, ?, 'pending')
710
+
(user_did, repo_did, record_nsid, record_rkey, status)
711
+
VALUES (?, ?, ?, ?, 'pending')
712
712
ON CONFLICT(user_did, record_nsid, record_rkey) DO UPDATE SET
713
713
status = 'pending',
714
714
repo_did = excluded.repo_did,
715
-
old_repo_at = excluded.old_repo_at,
716
715
updated_at = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')`,
717
-
userDid, repoDid, recordNsid, recordRkey, oldRepoAt,
716
+
userDid, repoDid, recordNsid, recordRkey,
718
717
)
719
718
return err
720
719
}
···
739
738
return nil
740
739
}
741
740
742
-
func UpdateDescription(e Execer, repoAt, newDescription string) error {
741
+
func UpdateDescription(e Execer, repoDid, newDescription string) error {
743
742
_, err := e.Exec(
744
-
`update repos set description = ? where at_uri = ?`, newDescription, repoAt)
743
+
`update repos set description = ? where repo_did = ?`, newDescription, repoDid)
745
744
return err
746
745
}
747
746
748
-
func UpdateSpindle(e Execer, repoAt string, spindle *string) error {
747
+
func UpdateSpindle(e Execer, repoDid string, spindle *string) error {
749
748
_, err := e.Exec(
750
-
`update repos set spindle = ? where at_uri = ?`, spindle, repoAt)
749
+
`update repos set spindle = ? where repo_did = ?`, spindle, repoDid)
751
750
return err
752
751
}
753
752
754
753
func SubscribeLabel(e Execer, rl *models.RepoLabel) error {
755
-
query := `insert or ignore into repo_labels (repo_at, label_at) values (?, ?)`
754
+
query := `insert or ignore into repo_labels (repo_did, label_at) values (?, ?)`
756
755
757
-
_, err := e.Exec(query, rl.RepoAt.String(), rl.LabelAt.String())
756
+
_, err := e.Exec(query, string(rl.RepoDid), rl.LabelAt.String())
758
757
return err
759
758
}
760
759
···
789
788
whereClause = " where " + strings.Join(conditions, " and ")
790
789
}
791
790
792
-
query := fmt.Sprintf(`select id, repo_at, label_at from repo_labels %s`, whereClause)
791
+
query := fmt.Sprintf(`select id, repo_did, label_at from repo_labels %s`, whereClause)
793
792
794
793
rows, err := e.Query(query, args...)
795
794
if err != nil {
···
801
800
for rows.Next() {
802
801
var label models.RepoLabel
803
802
804
-
err := rows.Scan(&label.Id, &label.RepoAt, &label.LabelAt)
803
+
err := rows.Scan(&label.Id, &label.RepoDid, &label.LabelAt)
805
804
if err != nil {
806
805
return nil, err
807
806
}
+7
-7
appview/db/site_deploys.go
+7
-7
appview/db/site_deploys.go
···
11
11
func AddSiteDeploy(e Execer, deploy *models.SiteDeploy) error {
12
12
result, err := e.Exec(`
13
13
insert into site_deploys (
14
-
repo_at,
14
+
repo_did,
15
15
branch,
16
16
dir,
17
17
commit_sha,
···
20
20
error
21
21
) values (?, ?, ?, ?, ?, ?, ?)
22
22
`,
23
-
deploy.RepoAt,
23
+
deploy.RepoDid,
24
24
deploy.Branch,
25
25
deploy.Dir,
26
26
deploy.CommitSHA,
···
42
42
}
43
43
44
44
// GetSiteDeploys returns recent deploy records for a repository, newest first.
45
-
func GetSiteDeploys(e Execer, repoAt string, limit int) ([]models.SiteDeploy, error) {
45
+
func GetSiteDeploys(e Execer, repoDid string, limit int) ([]models.SiteDeploy, error) {
46
46
if limit <= 0 {
47
47
limit = 20
48
48
}
···
50
50
rows, err := e.Query(`
51
51
select
52
52
id,
53
-
repo_at,
53
+
repo_did,
54
54
branch,
55
55
dir,
56
56
commit_sha,
···
59
59
error,
60
60
created_at
61
61
from site_deploys
62
-
where repo_at = ?
62
+
where repo_did = ?
63
63
order by created_at desc
64
64
limit ?
65
-
`, repoAt, limit)
65
+
`, repoDid, limit)
66
66
if err != nil {
67
67
return nil, fmt.Errorf("failed to query site deploys: %w", err)
68
68
}
···
75
75
76
76
if err := rows.Scan(
77
77
&d.Id,
78
-
&d.RepoAt,
78
+
&d.RepoDid,
79
79
&d.Branch,
80
80
&d.Dir,
81
81
&d.CommitSHA,
+27
-27
appview/db/sites.go
+27
-27
appview/db/sites.go
···
138
138
}
139
139
140
140
// GetRepoSiteConfig returns the site configuration for a repo, or nil if not configured.
141
-
func GetRepoSiteConfig(e Execer, repoAt string) (*models.RepoSite, error) {
141
+
func GetRepoSiteConfig(e Execer, repoDid string) (*models.RepoSite, error) {
142
142
row := e.QueryRow(`
143
-
select id, repo_at, branch, dir, is_index, created, updated
143
+
select id, repo_did, branch, dir, is_index, created, updated
144
144
from repo_sites
145
-
where repo_at = ?
146
-
`, repoAt)
145
+
where repo_did = ?
146
+
`, repoDid)
147
147
148
148
var s models.RepoSite
149
149
var isIndex int
150
150
var createdStr, updatedStr string
151
151
152
-
err := row.Scan(&s.ID, &s.RepoAt, &s.Branch, &s.Dir, &isIndex, &createdStr, &updatedStr)
152
+
err := row.Scan(&s.ID, &s.RepoDid, &s.Branch, &s.Dir, &isIndex, &createdStr, &updatedStr)
153
153
if errors.Is(err, sql.ErrNoRows) {
154
154
return nil, nil
155
155
}
···
173
173
}
174
174
175
175
// SetRepoSiteConfig inserts or replaces the site configuration for a repo.
176
-
func SetRepoSiteConfig(e Execer, repoAt, branch, dir string, isIndex bool) error {
176
+
func SetRepoSiteConfig(e Execer, repoDid, branch, dir string, isIndex bool) error {
177
177
isIndexInt := 0
178
178
if isIndex {
179
179
isIndexInt = 1
180
180
}
181
181
182
182
_, err := e.Exec(`
183
-
insert into repo_sites (repo_at, branch, dir, is_index, updated)
183
+
insert into repo_sites (repo_did, branch, dir, is_index, updated)
184
184
values (?, ?, ?, ?, strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
185
-
on conflict(repo_at) do update set
185
+
on conflict(repo_did) do update set
186
186
branch = excluded.branch,
187
187
dir = excluded.dir,
188
188
is_index = excluded.is_index,
189
189
updated = excluded.updated
190
-
`, repoAt, branch, dir, isIndexInt)
190
+
`, repoDid, branch, dir, isIndexInt)
191
191
return err
192
192
}
193
193
194
194
// DeleteRepoSiteConfig removes the site configuration for a repo.
195
-
func DeleteRepoSiteConfig(e Execer, repoAt string) error {
196
-
_, err := e.Exec(`delete from repo_sites where repo_at = ?`, repoAt)
195
+
func DeleteRepoSiteConfig(e Execer, repoDid string) error {
196
+
_, err := e.Exec(`delete from repo_sites where repo_did = ?`, repoDid)
197
197
return err
198
198
}
199
199
200
200
// GetRepoSiteConfigsForDid returns all site configurations for repos owned by a DID.
201
-
// RepoName is populated on each returned RepoSite.
201
+
// RepoRkey is populated on each returned RepoSite.
202
202
func GetRepoSiteConfigsForDid(e Execer, did string) ([]*models.RepoSite, error) {
203
203
rows, err := e.Query(`
204
-
select rs.id, rs.repo_at, r.name, rs.branch, rs.dir, rs.is_index, rs.created, rs.updated
204
+
select rs.id, rs.repo_did, r.rkey, rs.branch, rs.dir, rs.is_index, rs.created, rs.updated
205
205
from repo_sites rs
206
-
join repos r on r.at_uri = rs.repo_at
206
+
join repos r on r.repo_did = rs.repo_did
207
207
where r.did = ?
208
208
`, did)
209
209
if err != nil {
···
216
216
var s models.RepoSite
217
217
var isIndex int
218
218
var createdStr, updatedStr string
219
-
if err := rows.Scan(&s.ID, &s.RepoAt, &s.RepoName, &s.Branch, &s.Dir, &isIndex, &createdStr, &updatedStr); err != nil {
219
+
if err := rows.Scan(&s.ID, &s.RepoDid, &s.RepoRkey, &s.Branch, &s.Dir, &isIndex, &createdStr, &updatedStr); err != nil {
220
220
return nil, err
221
221
}
222
222
s.IsIndex = isIndex != 0
···
237
237
func DeleteRepoSiteConfigsForDid(e Execer, did string) error {
238
238
_, err := e.Exec(`
239
239
delete from repo_sites
240
-
where repo_at in (
241
-
select at_uri from repos where did = ?
240
+
where repo_did in (
241
+
select repo_did from repos where did = ?
242
242
)
243
243
`, did)
244
244
return err
245
245
}
246
246
247
-
// GetIndexRepoAtForDid returns the repo_at of the repo that currently holds
248
-
// is_index=1 for the given DID, excluding excludeRepoAt (the current repo).
247
+
// GetIndexRepoDidForDid returns the repo_did of the repo that currently holds
248
+
// is_index=1 for the given DID, excluding excludeRepoDid (the current repo).
249
249
// Returns "", nil if no other repo is the index site.
250
-
func GetIndexRepoAtForDid(e Execer, did, excludeRepoAt string) (string, error) {
250
+
func GetIndexRepoDidForDid(e Execer, did, excludeRepoDid string) (string, error) {
251
251
row := e.QueryRow(`
252
-
select rs.repo_at
252
+
select rs.repo_did
253
253
from repo_sites rs
254
-
join repos r on r.at_uri = rs.repo_at
254
+
join repos r on r.repo_did = rs.repo_did
255
255
where r.did = ?
256
256
and rs.is_index = 1
257
-
and rs.repo_at != ?
257
+
and rs.repo_did != ?
258
258
limit 1
259
-
`, did, excludeRepoAt)
259
+
`, did, excludeRepoDid)
260
260
261
-
var repoAt string
262
-
err := row.Scan(&repoAt)
261
+
var repoDid string
262
+
err := row.Scan(&repoDid)
263
263
if errors.Is(err, sql.ErrNoRows) {
264
264
return "", nil
265
265
}
266
266
if err != nil {
267
267
return "", err
268
268
}
269
-
return repoAt, nil
269
+
return repoDid, nil
270
270
}
+68
-70
appview/db/star.go
+68
-70
appview/db/star.go
···
1
1
package db
2
2
3
3
import (
4
-
"database/sql"
5
-
"errors"
6
4
"fmt"
7
5
"log"
8
6
"slices"
9
7
"strings"
10
8
"time"
11
9
12
-
"github.com/bluesky-social/indigo/atproto/syntax"
13
10
"tangled.org/core/appview/models"
14
11
"tangled.org/core/appview/pagination"
15
12
"tangled.org/core/orm"
16
13
)
17
14
18
15
func AddStar(e Execer, star *models.Star) error {
19
-
query := `insert or ignore into stars (did, subject_at, rkey) values (?, ?, ?)`
16
+
query := `insert or ignore into stars (did, subject_type, subject, rkey) values (?, ?, ?, ?)`
20
17
_, err := e.Exec(
21
18
query,
22
19
star.Did,
23
-
star.RepoAt.String(),
20
+
string(star.SubjectType),
21
+
star.Subject,
24
22
star.Rkey,
25
23
)
26
24
return err
27
25
}
28
26
29
27
// Get a star record
30
-
func GetStar(e Execer, did string, subjectAt syntax.ATURI) (*models.Star, error) {
28
+
func GetStar(e Execer, did string, subject string) (*models.Star, error) {
31
29
query := `
32
-
select did, subject_at, created, rkey
30
+
select did, subject_type, subject, created, rkey
33
31
from stars
34
-
where did = ? and subject_at = ?`
35
-
row := e.QueryRow(query, did, subjectAt)
32
+
where did = ? and subject = ?`
33
+
row := e.QueryRow(query, did, subject)
36
34
37
35
var star models.Star
38
36
var created string
39
-
err := row.Scan(&star.Did, &star.RepoAt, &created, &star.Rkey)
37
+
err := row.Scan(&star.Did, &star.SubjectType, &star.Subject, &created, &star.Rkey)
40
38
if err != nil {
41
39
return nil, err
42
40
}
···
52
50
return &star, nil
53
51
}
54
52
55
-
func GetStars(e Execer, subjectAt syntax.ATURI, page pagination.Page) ([]models.Star, error) {
53
+
func GetStars(e Execer, subject string, page pagination.Page) ([]models.Star, error) {
56
54
query := `
57
-
select did, subject_at, created, rkey
55
+
select did, subject_type, subject, created, rkey
58
56
from stars
59
-
where subject_at = ?
57
+
where subject = ?
60
58
order by created desc
61
59
limit ? offset ?
62
60
`
63
-
rows, err := e.Query(query, subjectAt, page.Limit, page.Offset)
61
+
rows, err := e.Query(query, subject, page.Limit, page.Offset)
64
62
if err != nil {
65
63
return nil, err
66
64
}
···
70
68
for rows.Next() {
71
69
var star models.Star
72
70
var created string
73
-
if err := rows.Scan(&star.Did, &star.RepoAt, &created, &star.Rkey); err != nil {
71
+
if err := rows.Scan(&star.Did, &star.SubjectType, &star.Subject, &created, &star.Rkey); err != nil {
74
72
return nil, err
75
73
}
76
74
···
85
83
}
86
84
87
85
// Remove a star
88
-
func DeleteStar(e Execer, did string, subjectAt syntax.ATURI) error {
89
-
_, err := e.Exec(`delete from stars where did = ? and subject_at = ?`, did, subjectAt)
86
+
func DeleteStar(e Execer, did string, subject string) error {
87
+
_, err := e.Exec(`delete from stars where did = ? and subject = ?`, did, subject)
90
88
return err
91
89
}
92
90
···
96
94
return err
97
95
}
98
96
99
-
func GetStarCount(e Execer, subjectAt syntax.ATURI) (int, error) {
97
+
func GetStarCount(e Execer, subjectType models.StarSubjectType, subject string) (int, error) {
100
98
stars := 0
101
99
err := e.QueryRow(
102
-
`select count(did) from stars where subject_at = ?`, subjectAt).Scan(&stars)
100
+
`select count(did) from stars where subject_type = ? and subject = ?`,
101
+
string(subjectType), subject,
102
+
).Scan(&stars)
103
103
if err != nil {
104
104
return 0, err
105
105
}
106
106
return stars, nil
107
107
}
108
108
109
-
// getStarStatuses returns a map of repo URIs to star status for a given user
109
+
// getStarStatuses returns a map of subjects to star status for a given user
110
110
// This is an internal helper function to avoid N+1 queries
111
-
func getStarStatuses(e Execer, userDid string, repoAts []syntax.ATURI) (map[string]bool, error) {
112
-
if len(repoAts) == 0 || userDid == "" {
111
+
func getStarStatuses(e Execer, userDid string, subjects []string) (map[string]bool, error) {
112
+
if len(subjects) == 0 || userDid == "" {
113
113
return make(map[string]bool), nil
114
114
}
115
115
116
-
placeholders := make([]string, len(repoAts))
117
-
args := make([]any, len(repoAts)+1)
116
+
placeholders := make([]string, len(subjects))
117
+
args := make([]any, len(subjects)+1)
118
118
args[0] = userDid
119
119
120
-
for i, repoAt := range repoAts {
120
+
for i, subj := range subjects {
121
121
placeholders[i] = "?"
122
-
args[i+1] = repoAt.String()
122
+
args[i+1] = subj
123
123
}
124
124
125
125
query := fmt.Sprintf(`
126
-
SELECT subject_at
126
+
SELECT subject
127
127
FROM stars
128
-
WHERE did = ? AND subject_at IN (%s)
128
+
WHERE did = ? AND subject IN (%s)
129
129
`, strings.Join(placeholders, ","))
130
130
131
131
rows, err := e.Query(query, args...)
···
135
135
defer rows.Close()
136
136
137
137
result := make(map[string]bool)
138
-
// Initialize all repos as not starred
139
-
for _, repoAt := range repoAts {
140
-
result[repoAt.String()] = false
138
+
// Initialize all subjects as not starred
139
+
for _, subj := range subjects {
140
+
result[subj] = false
141
141
}
142
142
143
-
// Mark starred repos as true
143
+
// Mark starred subjects as true
144
144
for rows.Next() {
145
-
var repoAt string
146
-
if err := rows.Scan(&repoAt); err != nil {
145
+
var subj string
146
+
if err := rows.Scan(&subj); err != nil {
147
147
return nil, err
148
148
}
149
-
result[repoAt] = true
149
+
result[subj] = true
150
150
}
151
151
152
152
return result, nil
153
153
}
154
154
155
-
func GetStarStatus(e Execer, userDid string, subjectAt syntax.ATURI) bool {
156
-
statuses, err := getStarStatuses(e, userDid, []syntax.ATURI{subjectAt})
155
+
func GetStarStatus(e Execer, userDid string, subject string) bool {
156
+
statuses, err := getStarStatuses(e, userDid, []string{subject})
157
157
if err != nil {
158
158
return false
159
159
}
160
-
return statuses[subjectAt.String()]
160
+
return statuses[subject]
161
161
}
162
162
163
-
// GetStarStatuses returns a map of repo URIs to star status for a given user
164
-
func GetStarStatuses(e Execer, userDid string, subjectAts []syntax.ATURI) (map[string]bool, error) {
165
-
return getStarStatuses(e, userDid, subjectAts)
163
+
// GetStarStatuses returns a map of subjects to star status for a given user
164
+
func GetStarStatuses(e Execer, userDid string, subjects []string) (map[string]bool, error) {
165
+
return getStarStatuses(e, userDid, subjects)
166
166
}
167
167
168
168
// GetRepoStars return a list of stars each holding target repository.
···
175
175
args = append(args, filter.Arg()...)
176
176
}
177
177
178
-
whereClause := ""
179
-
if conditions != nil {
180
-
whereClause = " where " + strings.Join(conditions, " and ")
181
-
}
178
+
conditions = append(conditions, "subject_type = 'repo'")
179
+
180
+
whereClause := " where " + strings.Join(conditions, " and ")
182
181
183
182
pageClause := ""
184
183
if page.Limit != 0 {
···
186
185
}
187
186
188
187
repoQuery := fmt.Sprintf(
189
-
`select did, subject_at, created, rkey
188
+
`select did, subject_type, subject, created, rkey
190
189
from stars
191
190
%s
192
191
order by created desc
···
204
203
for rows.Next() {
205
204
var star models.Star
206
205
var created string
207
-
err := rows.Scan(&star.Did, &star.RepoAt, &created, &star.Rkey)
206
+
err := rows.Scan(&star.Did, &star.SubjectType, &star.Subject, &created, &star.Rkey)
208
207
if err != nil {
209
208
return nil, err
210
209
}
···
214
213
star.Created = t
215
214
}
216
215
217
-
repoAt := string(star.RepoAt)
218
-
starMap[repoAt] = append(starMap[repoAt], star)
216
+
starMap[star.Subject] = append(starMap[star.Subject], star)
219
217
}
220
218
221
219
// populate *Repo in each star
···
230
228
return nil, nil
231
229
}
232
230
233
-
repos, err := GetRepos(e, orm.FilterIn("at_uri", args))
231
+
repos, err := GetRepos(e, orm.FilterIn("repo_did", args))
234
232
if err != nil {
235
233
return nil, err
236
234
}
237
235
238
236
var repoStars []models.RepoStar
239
237
for _, r := range repos {
240
-
if stars, ok := starMap[string(r.RepoAt())]; ok {
238
+
if stars, ok := starMap[r.RepoDid]; ok {
241
239
for _, star := range stars {
242
240
repoStars = append(repoStars, models.RepoStar{
243
241
Star: star,
···
275
273
276
274
repoQuery := fmt.Sprintf(`select count(1) from stars %s`, whereClause)
277
275
var count int64
278
-
err := e.QueryRow(repoQuery, args...).Scan(&count)
279
-
280
-
if !errors.Is(err, sql.ErrNoRows) && err != nil {
276
+
if err := e.QueryRow(repoQuery, args...).Scan(&count); err != nil {
281
277
return 0, err
282
278
}
283
279
···
286
282
287
283
// GetTopStarredReposLastWeek returns the top 8 most starred repositories from the last week
288
284
func GetTopStarredReposLastWeek(e Execer) ([]models.Repo, error) {
289
-
// first, get the top repo URIs by star count from the last week
285
+
// first, get the top repo DIDs by star count from the last week
290
286
query := `
291
287
with recent_starred_repos as (
292
-
select distinct subject_at
288
+
select distinct subject
293
289
from stars
294
290
where created >= datetime('now', '-7 days')
291
+
and subject_type = 'repo'
295
292
),
296
293
repo_star_counts as (
297
294
select
298
-
s.subject_at,
295
+
s.subject,
299
296
count(*) as stars_gained_last_week
300
297
from stars s
301
-
join recent_starred_repos rsr on s.subject_at = rsr.subject_at
298
+
join recent_starred_repos rsr on s.subject = rsr.subject
302
299
where s.created >= datetime('now', '-7 days')
303
-
group by s.subject_at
300
+
and s.subject_type = 'repo'
301
+
group by s.subject
304
302
)
305
-
select rsc.subject_at
303
+
select rsc.subject
306
304
from repo_star_counts rsc
307
305
order by rsc.stars_gained_last_week desc
308
306
limit 5
···
314
312
}
315
313
defer rows.Close()
316
314
317
-
var repoUris []string
315
+
var repoDids []string
318
316
for rows.Next() {
319
-
var repoUri string
320
-
err := rows.Scan(&repoUri)
317
+
var repoDid string
318
+
err := rows.Scan(&repoDid)
321
319
if err != nil {
322
320
return nil, err
323
321
}
324
-
repoUris = append(repoUris, repoUri)
322
+
repoDids = append(repoDids, repoDid)
325
323
}
326
324
327
325
if err := rows.Err(); err != nil {
328
326
return nil, err
329
327
}
330
328
331
-
if len(repoUris) == 0 {
329
+
if len(repoDids) == 0 {
332
330
return []models.Repo{}, nil
333
331
}
334
332
335
333
// get full repo data
336
-
repos, err := GetRepos(e, orm.FilterIn("at_uri", repoUris))
334
+
repos, err := GetRepos(e, orm.FilterIn("repo_did", repoDids))
337
335
if err != nil {
338
336
return nil, err
339
337
}
···
341
339
// sort repos by the original trending order
342
340
repoMap := make(map[string]models.Repo)
343
341
for _, repo := range repos {
344
-
repoMap[repo.RepoAt().String()] = repo
342
+
repoMap[repo.RepoDid] = repo
345
343
}
346
344
347
-
orderedRepos := make([]models.Repo, 0, len(repoUris))
348
-
for _, uri := range repoUris {
349
-
if repo, exists := repoMap[uri]; exists {
345
+
orderedRepos := make([]models.Repo, 0, len(repoDids))
346
+
for _, did := range repoDids {
347
+
if repo, exists := repoMap[did]; exists {
350
348
orderedRepos = append(orderedRepos, repo)
351
349
}
352
350
}
+4
-5
appview/db/timeline.go
+4
-5
appview/db/timeline.go
···
3
3
import (
4
4
"sort"
5
5
6
-
"github.com/bluesky-social/indigo/atproto/syntax"
7
6
"tangled.org/core/appview/models"
8
7
"tangled.org/core/appview/pagination"
9
8
"tangled.org/core/orm"
···
63
62
return nil, nil
64
63
}
65
64
66
-
var repoAts []syntax.ATURI
65
+
var repoDids []string
67
66
for _, r := range repos {
68
-
repoAts = append(repoAts, r.RepoAt())
67
+
repoDids = append(repoDids, r.RepoDid)
69
68
}
70
69
71
-
return GetStarStatuses(e, loggedInUserDid, repoAts)
70
+
return GetStarStatuses(e, loggedInUserDid, repoDids)
72
71
}
73
72
74
73
func getRepoStarInfo(repo *models.Repo, starStatuses map[string]bool) (bool, int64) {
75
74
var isStarred bool
76
75
if starStatuses != nil {
77
-
isStarred = starStatuses[repo.RepoAt().String()]
76
+
isStarred = starStatuses[repo.RepoDid]
78
77
}
79
78
80
79
var starCount int64
+8
-9
appview/db/webhooks.go
+8
-9
appview/db/webhooks.go
···
6
6
"strings"
7
7
"time"
8
8
9
-
"github.com/bluesky-social/indigo/atproto/syntax"
10
9
"tangled.org/core/appview/models"
11
10
"tangled.org/core/orm"
12
11
)
···
28
27
query := fmt.Sprintf(`
29
28
select
30
29
id,
31
-
repo_at,
30
+
repo_did,
32
31
url,
33
32
secret,
34
33
active,
···
55
54
56
55
err := rows.Scan(
57
56
&wh.Id,
58
-
&wh.RepoAt,
57
+
&wh.RepoDid,
59
58
&wh.Url,
60
59
&secret,
61
60
&active,
···
119
118
}
120
119
121
120
result, err := e.Exec(`
122
-
insert into webhooks (repo_at, url, secret, active, events)
121
+
insert into webhooks (repo_did, url, secret, active, events)
123
122
values (?, ?, ?, ?, ?)
124
-
`, webhook.RepoAt.String(), webhook.Url, webhook.Secret, active, eventsStr)
123
+
`, string(webhook.RepoDid), webhook.Url, webhook.Secret, active, eventsStr)
125
124
126
125
if err != nil {
127
126
return fmt.Errorf("failed to insert webhook: %w", err)
···
285
284
}
286
285
287
286
// GetWebhooksForRepo is a convenience function to get all webhooks for a repository
288
-
func GetWebhooksForRepo(e Execer, repoAt syntax.ATURI) ([]models.Webhook, error) {
289
-
return GetWebhooks(e, orm.FilterEq("repo_at", repoAt.String()))
287
+
func GetWebhooksForRepo(e Execer, repoDid string) ([]models.Webhook, error) {
288
+
return GetWebhooks(e, orm.FilterEq("repo_did", repoDid))
290
289
}
291
290
292
291
// GetActiveWebhooksForRepo returns only active webhooks for a repository
293
-
func GetActiveWebhooksForRepo(e Execer, repoAt syntax.ATURI) ([]models.Webhook, error) {
292
+
func GetActiveWebhooksForRepo(e Execer, repoDid string) ([]models.Webhook, error) {
294
293
return GetWebhooks(e,
295
-
orm.FilterEq("repo_at", repoAt.String()),
294
+
orm.FilterEq("repo_did", repoDid),
296
295
orm.FilterEq("active", 1),
297
296
)
298
297
}
+5
-6
appview/state/gfi.go
+5
-6
appview/state/gfi.go
···
4
4
"net/http"
5
5
"sort"
6
6
7
-
"github.com/bluesky-social/indigo/atproto/syntax"
8
7
"tangled.org/core/appview/db"
9
8
"tangled.org/core/appview/models"
10
9
"tangled.org/core/appview/pages"
···
48
47
49
48
repoUris := make([]string, 0, len(repoLabels))
50
49
for _, rl := range repoLabels {
51
-
repoUris = append(repoUris, rl.RepoAt.String())
50
+
repoUris = append(repoUris, string(rl.RepoDid))
52
51
}
53
52
54
53
allIssues, err := db.GetIssuesPaginated(
···
56
55
pagination.Page{
57
56
Limit: 500,
58
57
},
59
-
orm.FilterIn("repo_at", repoUris),
58
+
orm.FilterIn("repo_did", repoUris),
60
59
orm.FilterEq("open", 1),
61
60
)
62
61
if err != nil {
···
72
71
}
73
72
}
74
73
75
-
repoGroups := make(map[syntax.ATURI]*models.RepoGroup)
74
+
repoGroups := make(map[string]*models.RepoGroup)
76
75
for _, issue := range goodFirstIssues {
77
-
if group, exists := repoGroups[issue.Repo.RepoAt()]; exists {
76
+
if group, exists := repoGroups[issue.Repo.RepoDid]; exists {
78
77
group.Issues = append(group.Issues, issue)
79
78
} else {
80
-
repoGroups[issue.Repo.RepoAt()] = &models.RepoGroup{
79
+
repoGroups[issue.Repo.RepoDid] = &models.RepoGroup{
81
80
Repo: issue.Repo,
82
81
Issues: []models.Issue{issue},
83
82
}
+47
-16
appview/state/star.go
+47
-16
appview/state/star.go
···
1
1
package state
2
2
3
3
import (
4
+
"fmt"
5
+
"log"
4
6
"net/http"
5
7
"time"
6
8
···
11
13
"tangled.org/core/appview/db"
12
14
"tangled.org/core/appview/models"
13
15
"tangled.org/core/appview/pages"
14
-
"tangled.org/core/orm"
15
16
"tangled.org/core/tid"
16
17
)
17
18
19
+
func resolveStarSubject(d db.Execer, subjectUri syntax.ATURI) (models.StarSubjectType, string, *tangled.FeedStar_Subject, error) {
20
+
collection := subjectUri.Collection()
21
+
22
+
switch collection.String() {
23
+
case tangled.RepoNSID:
24
+
repo, err := db.GetRepoByAtUri(d, subjectUri.String())
25
+
if err != nil {
26
+
return "", "", nil, err
27
+
}
28
+
if repo.RepoDid == "" {
29
+
return "", "", nil, fmt.Errorf("repo has no DID: %s", subjectUri)
30
+
}
31
+
subject := &tangled.FeedStar_Subject{
32
+
FeedStar_Repo: &tangled.FeedStar_Repo{Did: repo.RepoDid},
33
+
}
34
+
return models.StarSubjectRepo, repo.RepoDid, subject, nil
35
+
36
+
case tangled.StringNSID:
37
+
uri := subjectUri.String()
38
+
subject := &tangled.FeedStar_Subject{
39
+
FeedStar_String: &tangled.FeedStar_String{Uri: uri},
40
+
}
41
+
return models.StarSubjectString, uri, subject, nil
42
+
43
+
default:
44
+
return "", "", nil, fmt.Errorf("unsupported star subject collection: %s", collection)
45
+
}
46
+
}
47
+
18
48
func (s *State) Star(w http.ResponseWriter, r *http.Request) {
19
49
l := s.logger.With("handler", "Star")
20
50
currentUser := s.oauth.GetMultiAccountUser(r)
···
31
61
return
32
62
}
33
63
64
+
subjectType, subjectKey, starSubject, err := resolveStarSubject(s.db, subjectUri)
65
+
if err != nil {
66
+
log.Println("failed to resolve star subject", err)
67
+
return
68
+
}
69
+
34
70
client, err := s.oauth.AuthorizedClient(r)
35
71
if err != nil {
36
72
l.Error("failed to authorize client", "err", err)
···
44
80
createdAt := time.Now().Format(time.RFC3339)
45
81
rkey := tid.TID()
46
82
47
-
subjectStr := subjectUri.String()
48
83
starRecord := &tangled.FeedStar{
49
84
CreatedAt: createdAt,
50
-
Subject: &subjectStr,
51
-
}
52
-
repo, err := db.GetRepo(s.db, orm.FilterEq("at_uri", subjectUri.String()))
53
-
if err == nil && repo.RepoDid != "" {
54
-
starRecord.SubjectDid = &repo.RepoDid
85
+
Subject: starSubject,
55
86
}
56
87
57
88
resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{
···
67
98
l.Info("created atproto record", "uri", resp.Uri)
68
99
69
100
star := &models.Star{
70
-
Did: currentUser.Did,
71
-
RepoAt: subjectUri,
72
-
Rkey: rkey,
101
+
Did: currentUser.Did,
102
+
SubjectType: subjectType,
103
+
Subject: subjectKey,
104
+
Rkey: rkey,
73
105
}
74
106
75
107
err = db.AddStar(s.db, star)
···
78
110
return
79
111
}
80
112
81
-
starCount, err := db.GetStarCount(s.db, subjectUri)
113
+
starCount, err := db.GetStarCount(s.db, subjectType, subjectKey)
82
114
if err != nil {
83
-
l.Error("failed to get star count", "subjectUri", subjectUri, "err", err)
115
+
l.Error("failed to get star count", "subject", subjectKey, "err", err)
84
116
}
85
117
86
118
s.notifier.NewStar(r.Context(), star)
···
95
127
return
96
128
case http.MethodDelete:
97
129
// find the record in the db
98
-
star, err := db.GetStar(s.db, currentUser.Did, subjectUri)
130
+
star, err := db.GetStar(s.db, currentUser.Did, subjectKey)
99
131
if err != nil {
100
132
l.Error("failed to get star relationship", "err", err)
101
133
return
···
118
150
// this is not an issue, the firehose event might have already done this
119
151
}
120
152
121
-
starCount, err := db.GetStarCount(s.db, subjectUri)
153
+
starCount, err := db.GetStarCount(s.db, subjectType, subjectKey)
122
154
if err != nil {
123
-
l.Error("failed to get star count", "subjectUri", subjectUri, "err", err)
155
+
l.Error("failed to get star count", "subject", subjectKey, "err", err)
124
156
return
125
157
}
126
158
···
135
167
136
168
return
137
169
}
138
-
139
170
}
History
1 round
0 comments
oyster.cafe
submitted
#0
1 commit
expand
collapse
appview/db: queries use repo_did lookups
Lewis: May this revision serve well! <lewis@tangled.org>
no conflicts, ready to merge