Skip to content

Commit 7613ef5

Browse files
author
Miguel Acero
committed
internal/postgres: update UpsertSearchDocument to prefer non-incompatible 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 <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent c6b82ee commit 7613ef5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

internal/postgres/search.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,7 @@ var upsertSearchStatement = fmt.Sprintf(`
530530
AND p.version = m.version
531531
WHERE
532532
p.path = $1
533-
ORDER BY
534-
-- Order the versions by release then prerelease.
535-
-- The default version should be the first release
536-
-- version available, if one exists.
537-
m.version_type = 'release' DESC,
538-
m.sort_version DESC,
539-
m.module_path DESC
533+
%s
540534
LIMIT 1
541535
ON CONFLICT (package_path)
542536
DO UPDATE SET
@@ -556,7 +550,7 @@ var upsertSearchStatement = fmt.Sprintf(`
556550
THEN search_documents.version_updated_at
557551
ELSE CURRENT_TIMESTAMP
558552
END)
559-
;`, hllRegisterCount)
553+
;`, hllRegisterCount, orderByLatest)
560554

561555
// UpsertSearchDocuments adds search information for mod ot the search_documents table.
562556
func UpsertSearchDocuments(ctx context.Context, db *database.DB, mod *internal.Module) (err error) {

internal/postgres/search_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,11 @@ func TestUpsertSearchDocument(t *testing.T) {
731731
}
732732

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

736741
insertModule("v0.5.0", true)

0 commit comments

Comments
 (0)