Skip to content

Commit

Permalink
repology: verify all outdated entries are indeed outdated
Browse files Browse the repository at this point in the history
Resolves: #30
Signed-off-by: Arthur Zamarin <[email protected]>
  • Loading branch information
arthurzam committed Jul 8, 2024
1 parent e3ea34c commit f7ba291
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/portage/repology/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"net/http"
"regexp"
"slices"
"soko/pkg/config"
"soko/pkg/database"
"soko/pkg/models"
Expand Down Expand Up @@ -37,6 +38,7 @@ func UpdateOutdated() {
for letter := 'a'; letter <= 'z'; letter++ {
outdated.getOutdatedStartingWith(letter)
}
outdated.compareAgainstVersions()

// Update the database
if len(outdated.outdatedVersions) > 0 {
Expand Down Expand Up @@ -110,6 +112,7 @@ func newOutdatedCheck() outdatedCheck {

// getOutdatedStartingWith gets all outdated packages starting with the given letter
func (o *outdatedCheck) getOutdatedStartingWith(letter rune) {
slog.Debug("Fetching outdated packages", slog.String("letter", string(letter)))
repoPackages, err := parseRepologyData(letter)
if err != nil {
slog.Error("Error while fetching repology data", slog.String("letter", string(letter)), slog.Any("err", err))
Expand Down Expand Up @@ -176,6 +179,50 @@ func (o *outdatedCheck) getOutdatedStartingWith(letter rune) {
}
}

func (o *outdatedCheck) compareAgainstVersions() {
packagesMap := make(map[string]*models.OutdatedPackages, len(o.outdatedVersions))
packages := make([]*models.Package, len(o.outdatedVersions))
for i, p := range o.outdatedVersions {
packages[i] = &models.Package{Atom: p.Atom}
packagesMap[p.Atom] = p
}

err := database.DBCon.Model(&packages).WherePK().Relation("Versions").Select()
if err != nil {
slog.Error("Failed fetching packages", slog.Any("err", err))
return
}

o.outdatedVersions = make([]*models.OutdatedPackages, 0, len(packages))
nextPackage:
for _, p := range packages {
pkg := packagesMap[p.Atom]
if len(p.Versions) == 0 {
continue
}

latest := models.Version{Version: pkg.NewestVersion}
if latest.Version == "" {
continue
}
currentLatest := p.Versions[0]
for _, v := range p.Versions {
if slices.Contains(v.Properties, "live") {
continue
}
if strings.HasPrefix(v.Version, latest.Version) || !latest.GreaterThan(*v) {
continue nextPackage
}
if v.GreaterThan(*currentLatest) {
currentLatest = v
}
}
pkg.GentooVersion = currentLatest.Version
o.outdatedVersions = append(o.outdatedVersions, pkg)
}
slog.Debug("Filtered outdated", slog.Int("before", len(packagesMap)), slog.Int("after", len(o.outdatedVersions)))
}

// parseRepologyData gets the json from given url and parses it
func parseRepologyData(letter rune) (Packages, error) {
err := clientRateLimiter.Wait(context.Background())
Expand Down

0 comments on commit f7ba291

Please sign in to comment.