fix(metadata): treat .mod and .info names as metadata for Go only

GetStats, the package list and the stats snapshots dropped any registry's
names that end in .mod or .info. An npm or PyPI package with such a name
vanished from the counts. The filter now matches IsMetadataEntry.
This commit is contained in:
2026-11-24 02:43:17 +00:00
parent 1b00236749
commit 5f4bdbed80
5 changed files with 46 additions and 15 deletions
+15 -2
View File
@@ -3,6 +3,7 @@ package gormstore
import (
"context"
"sort"
"strings"
"time"
"github.com/lukaszraczylo/gohoarder/pkg/errors"
@@ -20,8 +21,20 @@ const (
// artifactPackages limits a query on packages to cache artifacts: no metadata
// pages and no Go .mod/.info files, as GetStats counts them.
func artifactPackages(db *gorm.DB) *gorm.DB {
return db.Where("version NOT IN ?", metadata.MetadataVersions).
Where("name NOT LIKE ?", "%.mod").Where("name NOT LIKE ?", "%.info")
cond, args := notGoMetadataName()
return db.Where("version NOT IN ?", metadata.MetadataVersions).Where(cond, args...)
}
// notGoMetadataName is the condition that drops Go .mod/.info rows; the suffixes mean
// metadata for Go only, as metadata.IsMetadataEntry has it.
func notGoMetadataName() (string, []interface{}) {
conds := make([]string, 0, len(metadata.MetadataNameSuffixes))
args := []interface{}{metadata.GoRegistry}
for _, suffix := range metadata.MetadataNameSuffixes {
conds = append(conds, "name LIKE ?")
args = append(args, "%"+suffix)
}
return "NOT (registry_id IN (SELECT id FROM registries WHERE name = ?) AND (" + strings.Join(conds, " OR ") + "))", args
}
func dayString(t time.Time) string { return t.UTC().Format(metadata.StatsSnapshotDateLayout) }