Signed-off-by: Will did:plc:dadhhalkfcq3gucaq25hjqon
+47
Diff
round #1
+46
appview/db/repos.go
+46
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
+
i = 0
308
+
for _, r := range repoMap {
309
+
forkArgs[i] = r.RepoDid
310
+
i++
311
+
}
312
+
313
+
forksCountQuery := fmt.Sprintf(
314
+
`select source, count(1) from repos where source in (%s) group by source`,
315
+
forksInClause,
316
+
)
317
+
318
+
rows, err = e.Query(forksCountQuery, forkArgs...)
319
+
if err != nil {
320
+
return nil, fmt.Errorf("failed to execute fork-count query: %w", err)
321
+
}
322
+
defer rows.Close()
323
+
324
+
repoDidMap := make(map[string]syntax.ATURI)
325
+
for aturi, repo := range repoMap {
326
+
repoDidMap[repo.RepoDid] = aturi
327
+
}
328
+
329
+
for rows.Next() {
330
+
var repodid string
331
+
var count int
332
+
if err := rows.Scan(&repodid, &count); err != nil {
333
+
log.Println("err", "err", err)
334
+
continue
335
+
}
336
+
337
+
atURI, ok := repoDidMap[repodid]
338
+
if !ok {
339
+
continue
340
+
}
341
+
342
+
if r, ok := repoMap[atURI]; ok {
343
+
r.RepoStats.ForkCount = count
344
+
}
345
+
}
346
+
if err = rows.Err(); err != nil {
347
+
return nil, fmt.Errorf("failed to execute fork-count query: %w", err)
348
+
}
349
+
304
350
var repos []models.Repo
305
351
for _, r := range repoMap {
306
352
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>