Skip to content

Commit

Permalink
internal/postgres: update UpsertSearchDocument to prefer non-incompat…
Browse files Browse the repository at this point in the history
…ible modules

Updates UpsertSearchDocument's to use orderByLatest in the query to
prefer compatible modules when inserting into the search_documents
table. This change updates the versions seen in the search results once
the module is reprocessed.

before: https://i.imgur.com/A7boYiC.png
after: https://i.imgur.com/ZLdTuex.png

Updates golang/go#37714

Change-Id: I527e6f157c5ddfe2a73e561f0be78738d97bb2fc
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/249278
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 c6b82ee commit 7613ef5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 2 additions & 8 deletions internal/postgres/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,13 +530,7 @@ var upsertSearchStatement = fmt.Sprintf(`
AND p.version = m.version
WHERE
p.path = $1
ORDER BY
-- Order the versions by release then prerelease.
-- The default version should be the first release
-- version available, if one exists.
m.version_type = 'release' DESC,
m.sort_version DESC,
m.module_path DESC
%s
LIMIT 1
ON CONFLICT (package_path)
DO UPDATE SET
Expand All @@ -556,7 +550,7 @@ var upsertSearchStatement = fmt.Sprintf(`
THEN search_documents.version_updated_at
ELSE CURRENT_TIMESTAMP
END)
;`, hllRegisterCount)
;`, hllRegisterCount, orderByLatest)

// UpsertSearchDocuments adds search information for mod ot the search_documents table.
func UpsertSearchDocuments(ctx context.Context, db *database.DB, mod *internal.Module) (err error) {
Expand Down
5 changes: 5 additions & 0 deletions internal/postgres/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,11 @@ func TestUpsertSearchDocument(t *testing.T) {
}

insertModule("v1.0.0", false)

// Ensures the row updated in the search_document table for a given module
// is updated with a version that prefers non-incompatible modules. (The
// latest version after this insertion should remain v1.0.0)
insertModule("v2.0.0+incompatible", false)
sdOriginal := getSearchDocument()

insertModule("v0.5.0", true)
Expand Down

0 comments on commit 7613ef5

Please sign in to comment.