Skip to content

Commit

Permalink
internal/postgres: update LegacyGetModuleInfo to prefer non-incompati…
Browse files Browse the repository at this point in the history
…ble modules

Updates LegacyGetModuleInfo to use orderByLatest in the query to prefer
compatible modules.

Updates golang/go#37714

Change-Id: I83bbbf3a8f5753533f3b2d8d5e329e82400951df
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/249277
Run-TryBot: Miguel Acero <acero@google.com>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
Miguel Acero committed Aug 19, 2020
1 parent 56517e4 commit c6b82ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
15 changes: 4 additions & 11 deletions internal/postgres/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,15 @@ func (db *DB) LegacyGetModuleInfo(ctx context.Context, modulePath string, versio
redistributable,
has_go_mod
FROM
modules`
modules m`

args := []interface{}{modulePath}
if version == internal.LatestVersion {
query += `
WHERE module_path = $1
ORDER BY
-- Order the versions by release then prerelease.
-- The default version should be the first release
-- version available, if one exists.
version_type = 'release' DESC,
sort_version DESC
LIMIT 1;`
query += fmt.Sprintf(`
WHERE m.module_path = $1 %s LIMIT 1;`, orderByLatest)
} else {
query += `
WHERE module_path = $1 AND version = $2;`
WHERE m.module_path = $1 AND m.version = $2;`
args = append(args, version)
}

Expand Down
1 change: 1 addition & 0 deletions internal/postgres/details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestPostgres_GetVersionInfo_Latest(t *testing.T) {
sample.Module("mod.1", "v1.1.0-alpha.1", sample.Suffix),
sample.Module("mod.1", "v1.0.0", sample.Suffix),
sample.Module("mod.1", "v1.0.0-20190311183353-d8887717615a", sample.Suffix),
sample.Module("mod.1", "v2.0.0+incompatible", sample.Suffix),
},
wantIndex: 1,
},
Expand Down

0 comments on commit c6b82ee

Please sign in to comment.