mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-24 09:59:24 +02:00
fix(packages): list highest CRAN version in PACKAGES index (#39793)
Fixes https://github.com/go-gitea/gitea/issues/35728 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
42b1f95261
commit
efb0b34395
6 files changed
+74
-41
No files matched your search
@@ -58,18 +58,30 @@ func (opts *SearchOptions) toConds() builder.Cond {
|
||||
return cond
|
||||
}
|
||||
|
||||
func SearchLatestVersions(ctx context.Context, opts *SearchOptions) ([]*packages.PackageVersion, error) {
|
||||
sess := db.GetEngine(ctx).
|
||||
func SearchLatestVersions(ctx context.Context, opts *SearchOptions) (latest []*packages.PackageVersion, err error) {
|
||||
var allPkgVers []*packages.PackageVersion
|
||||
err = db.GetEngine(ctx).
|
||||
Table("package_version").
|
||||
Select("package_version.*").
|
||||
Join("LEFT", "package_version pv2", builder.Expr("package_version.package_id = pv2.package_id AND pv2.is_internal = ? AND (package_version.created_unix < pv2.created_unix OR (package_version.created_unix = pv2.created_unix AND package_version.id < pv2.id))", false)).
|
||||
Join("INNER", "package", "package.id = package_version.package_id").
|
||||
Join("INNER", "package_file", "package_file.version_id = package_version.id").
|
||||
Where(opts.toConds().And(builder.Expr("pv2.id IS NULL"))).
|
||||
Asc("package.name")
|
||||
Where(opts.toConds()).
|
||||
Asc("package.name", "package.id").
|
||||
Find(&allPkgVers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pvs := make([]*packages.PackageVersion, 0, 10)
|
||||
return pvs, sess.Find(&pvs)
|
||||
// SQL can't order R version strings, so pick the highest version per package here
|
||||
for _, pv := range allPkgVers {
|
||||
curIdx := len(latest) - 1
|
||||
if curIdx == -1 || latest[curIdx].PackageID != pv.PackageID {
|
||||
latest = append(latest, pv) // start a new package version
|
||||
} else if cran_module.CompareVersions(pv.Version, latest[curIdx].Version) > 0 {
|
||||
latest[curIdx] = pv // replace with a higher version
|
||||
}
|
||||
}
|
||||
return latest, nil
|
||||
}
|
||||
|
||||
func SearchFile(ctx context.Context, opts *SearchOptions) (*packages.PackageFile, error) {
|
||||
|
||||
Reference in new issue
Block a user