fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

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

shards: populate RepoList.Stats.Repos (#605)

Previously this was only populated by the web package for serving a
specific endpoint. We now populate it in all places we do aggregation.

Test Plan: updated unit tests. Additionally loaded zoekt-webserver then
added to the index a repository which required 2 shards to index. The
repository count shown only increased by 1.

+18 -7
+3
api.go
··· 684 684 // Statistics of a (collection of) repositories. 685 685 type RepoStats struct { 686 686 // Repos is used for aggregrating the number of repositories. 687 + // 688 + // Note: This field is not populated on RepoListEntry.Stats (individual) but 689 + // only for RepoList.Stats (aggregate). 687 690 Repos int 688 691 689 692 // Shards is the total number of search shards.
+4
eval.go
··· 731 731 732 732 } 733 733 734 + // Only one of these fields is populated and in all cases the size of that 735 + // field is the number of Repos in this shard. 736 + l.Stats.Repos = len(l.Repos) + len(l.Minimal) + len(l.ReposMap) 737 + 734 738 return &l, nil 735 739 } 736 740
+2
index_test.go
··· 1711 1711 }, 1712 1712 }}, 1713 1713 Stats: RepoStats{ 1714 + Repos: 1, 1714 1715 Documents: 4, 1715 1716 ContentBytes: 68, 1716 1717 Shards: 1, ··· 1772 1773 }, 1773 1774 }, 1774 1775 Stats: RepoStats{ 1776 + Repos: 1, 1775 1777 Shards: 1, 1776 1778 Documents: 4, 1777 1779 IndexBytes: 412,
+7
shards/shards.go
··· 987 987 agg.Repos = append(agg.Repos, r) 988 988 } 989 989 990 + // Only one of these fields is populated and in all cases the size of that 991 + // field is the number of Repos. 992 + // 993 + // Note: we don't just add individual Stats.Repos since a repository can 994 + // have multiple shards. 995 + agg.Stats.Repos = len(uniq) + len(agg.Minimal) + len(agg.ReposMap) 996 + 990 997 if isAll && len(agg.Repos) > 0 { 991 998 reportListAllMetrics(agg.Repos) 992 999 }
+1
shards/shards_test.go
··· 472 472 473 473 aggStats := stats 474 474 aggStats.Add(&aggStats) // since both repos have the exact same stats, this works 475 + aggStats.Repos = 2 // Add doesn't populate Repos, this is done in Shards based on the response sizes. 475 476 476 477 for _, tc := range []struct { 477 478 name string
+1 -7
web/server.go
··· 349 349 return nil, err 350 350 } 351 351 352 - stats = &zoekt.RepoStats{} 353 - names := map[string]struct{}{} 354 - for _, r := range repos.Repos { 355 - stats.Add(&r.Stats) 356 - names[r.Repository.Name] = struct{}{} 357 - } 358 - stats.Repos = len(names) 352 + stats = &repos.Stats 359 353 360 354 s.lastStatsMu.Lock() 361 355 s.lastStatsTS = time.Now()