mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
fix(metadata): leave Go metadata files out of the registry stats
GetRegistryStats counted Go .mod and .info rows while GetStats and the package rows left them out. The overview registry table therefore showed more Go packages than the totals. Both stores now use the artifact filter.
This commit is contained in:
@@ -132,7 +132,7 @@ func (s *Store) GetRegistryStats(ctx context.Context) ([]metadata.RegistryStat,
|
||||
byRegistry := map[string]*metadata.RegistryStat{}
|
||||
var order []string
|
||||
for _, p := range all {
|
||||
if metadata.IsMetadataVersion(p.Version) {
|
||||
if metadata.IsMetadataEntry(p.Registry, p.Name, p.Version) {
|
||||
continue
|
||||
}
|
||||
st, ok := byRegistry[p.Registry]
|
||||
|
||||
@@ -353,9 +353,8 @@ func (s *GORMStoreV2) GetRegistryStats(ctx context.Context) ([]metadata.Registry
|
||||
Size int64
|
||||
Downloads int64
|
||||
}
|
||||
if err := s.db.WithContext(ctx).Model(&PackageModel{}).
|
||||
if err := artifactPackages(s.db.WithContext(ctx).Model(&PackageModel{})).
|
||||
Select("registry_id, COUNT(*) AS count, COALESCE(SUM(size), 0) AS size, COALESCE(SUM(access_count), 0) AS downloads").
|
||||
Where("version NOT IN ?", metadata.MetadataVersions).
|
||||
Group("registry_id").Order("registry_id").
|
||||
Scan(&rows).Error; err != nil {
|
||||
return nil, errors.Wrap(err, errors.ErrCodeStorageFailure, "failed to aggregate registry stats")
|
||||
|
||||
@@ -296,7 +296,7 @@ func checkRegistryStats(t *testing.T, store *GORMStoreV2) {
|
||||
got[s.Registry] = s
|
||||
}
|
||||
require.Equal(t, metadata.RegistryStat{Registry: "npm", Count: 6, Size: 100 + 110 + 300 + 900 + 10 + 20, Downloads: 3 + 1 + 7}, got["npm"], "the list page is excluded")
|
||||
require.Equal(t, metadata.RegistryStat{Registry: "go", Count: 5, Size: 500 + 10 + 5 + 520 + 40, Downloads: 3}, got["go"])
|
||||
require.Equal(t, metadata.RegistryStat{Registry: "go", Count: 3, Size: 500 + 520 + 40, Downloads: 3}, got["go"], "the .mod and .info files are excluded, as in GetStats")
|
||||
require.Equal(t, metadata.RegistryStat{Registry: "pypi", Count: 2, Size: 80, Downloads: 4}, got["pypi"])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user