Signed-off-by: Will did:plc:dadhhalkfcq3gucaq25hjqon
+44
Diff
round #2
+43
appview/db/repos.go
+43
appview/db/repos.go
···
301
301
return nil, fmt.Errorf("failed to execute pulls-count query: %w", err)
302
302
}
303
303
304
+
// get forks
305
+
forksInClause := strings.TrimSuffix(strings.Repeat("?, ", len(repoMap)), ", ")
306
+
forkArgs := make([]any, len(repoMap))
307
+
repoDidMap := make(map[string]syntax.ATURI)
308
+
i = 0
309
+
for aturi, r := range repoMap {
310
+
forkArgs[i] = r.RepoDid
311
+
repoDidMap[r.RepoDid] = aturi
312
+
i++
313
+
}
314
+
315
+
forksCountQuery := fmt.Sprintf(
316
+
`select source, count(1) from repos where source in (%s) group by source`,
317
+
forksInClause,
318
+
)
319
+
320
+
rows, err = e.Query(forksCountQuery, forkArgs...)
321
+
if err != nil {
322
+
return nil, fmt.Errorf("failed to execute fork-count query: %w", err)
323
+
}
324
+
defer rows.Close()
325
+
326
+
for rows.Next() {
327
+
var repodid string
328
+
var count int
329
+
if err := rows.Scan(&repodid, &count); err != nil {
330
+
log.Println("err", "err", err)
331
+
continue
332
+
}
333
+
334
+
atURI, ok := repoDidMap[repodid]
335
+
if !ok {
336
+
continue
337
+
}
338
+
339
+
if r, ok := repoMap[atURI]; ok {
340
+
r.RepoStats.ForkCount = count
341
+
}
342
+
}
343
+
if err = rows.Err(); err != nil {
344
+
return nil, fmt.Errorf("failed to execute fork-count query: %w", err)
345
+
}
346
+
304
347
var repos []models.Repo
305
348
for _, r := range repoMap {
306
349
repos = append(repos, *r)
History
4 rounds
0 comments
willdot.net
submitted
#3
1 commit
expand
collapse
appview/db/repos: calculate the fork count of a repo
Signed-off-by: Will <did:plc:dadhhalkfcq3gucaq25hjqon>
merge conflicts detected
expand
collapse
expand
collapse
- appview/db/repos.go:301
- appview/models/repo.go:97
expand 0 comments
willdot.net
submitted
#2
1 commit
expand
collapse
appview/db/repos: calculate the fork count of a repo
Signed-off-by: Will <did:plc:dadhhalkfcq3gucaq25hjqon>
expand 0 comments
willdot.net
submitted
#1
1 commit
expand
collapse
appview/db/repos: calculate the fork count of a repo
Signed-off-by: Will <did:plc:dadhhalkfcq3gucaq25hjqon>
expand 0 comments
willdot.net
submitted
#0
1 commit
expand
collapse
appview/db/repos: calculate the fork count of a repo
Signed-off-by: Will <did:plc:dadhhalkfcq3gucaq25hjqon>