Skip to content

Commit

Permalink
internal/postgres: update GetPathInfo to prefer non-incompatible modules
Browse files Browse the repository at this point in the history
Updates GetPathInfo to use orderByLatest in the query to prefer
compatible modules.

Updates golang/go#37714

Change-Id: I89fd654c414f860a2f8a327ff9a8fde07fd35120
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/249119
Run-TryBot: Miguel Acero <acero@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
  • Loading branch information
Miguel Acero committed Aug 19, 2020
1 parent a1d3b21 commit 7c0bed0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 2 additions & 5 deletions internal/postgres/path.go
Expand Up @@ -63,12 +63,9 @@ func (db *DB) GetPathInfo(ctx context.Context, path, inModulePath, inVersion str
%s
WHERE p.path = $1
%s
ORDER BY
m.version_type = 'release' DESC,
m.sort_version DESC,
m.module_path DESC
%s
LIMIT 1
`, joinStmt, strings.Join(constraints, " "))
`, joinStmt, strings.Join(constraints, " "), orderByLatest)
err = db.db.QueryRow(ctx, query, args...).Scan(&outModulePath, &outVersion, &isPackage)
switch err {
case sql.ErrNoRows:
Expand Down
10 changes: 10 additions & 0 deletions internal/postgres/path_test.go
Expand Up @@ -31,7 +31,9 @@ func TestGetPathInfo(t *testing.T) {
{"m.com", "v1.0.1", "dir/a", false},
{"m.com", "v1.1.0", "a/b", false},
{"m.com", "v1.2.0-pre", "a", true},
{"m.com", "v2.0.0+incompatible", "a", false},
{"m.com/a", "v1.1.0", "b", false},
{"m.com/b", "v2.0.0+incompatible", "a", true},
} {
vtype, err := version.ParseType(testModule.version)
if err != nil {
Expand Down Expand Up @@ -166,6 +168,14 @@ func TestGetPathInfo(t *testing.T) {
wantVersion: "v1.2.0-pre",
wantIsPackage: true,
},
{
name: "incompatible module",
path: "m.com/b",
version: "master",
wantModule: "m.com/b",
wantVersion: "v2.0.0+incompatible",
wantIsPackage: false,
},
} {
t.Run(test.name, func(t *testing.T) {
if test.module == "" {
Expand Down

0 comments on commit 7c0bed0

Please sign in to comment.