diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-08-16 08:25:09 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2021-08-16 15:32:11 +0000 |
| commit | 729fee3ca83f69fad10cd56429a9d010034ad320 (patch) | |
| tree | 039b6effb273c01ecdeb78dee21da5bc119ddb11 /internal/postgres/insert_module.go | |
| parent | 1a91d325f56b7a8e88d3855c12705a9395d9195c (diff) | |
| download | go-x-pkgsite-729fee3ca83f69fad10cd56429a9d010034ad320.tar.xz | |
internal/postgres: don't insert into search if a prefix
In ReconcileSearch, don't insert a module into search_documents if
there is already a module path that is a suffix of the current one.
This avoids cases like the following:
1. github.com/araalinetworks/api, which has a golang package, is
fetched and added to search_documents.
2. github.com/araalinetworks/api/golang is fetched and added to
search_documents, correctly replacing github.com/araalinetworks/api
because it is a longer module path.
3. Another version of github.com/araalinetworks/api is fetched. It is
bad, so it isn't inserted in the usual way, but ReconcileSearch
re-inserts the latest good version, which overwrites the longer
module path inserted in step 2.
Change-Id: If8ae59acfde7838c0ea48882d6beb0a457e125db
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/342469
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/insert_module.go')
| -rw-r--r-- | internal/postgres/insert_module.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 073ab41b..d977141c 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -639,8 +639,9 @@ func insertReadmes(ctx context.Context, db *database.DB, // ReconcileSearch reconciles the search data for modulePath. If the module is // alternative or has no good versions, it removes search data. Otherwise, if -// the latest good version doesn't match the version in search_documents, and it -// inserts the latest good version into search_documents and imports_unique. +// the latest good version doesn't match the version in search_documents, +// and the module path is not a prefix of one already in search_documents, +// it inserts the latest good version into search_documents and imports_unique. // The version and status arguments should come from the module currently being // fetched. They are used to determine if the module is alternative. func (db *DB) ReconcileSearch(ctx context.Context, modulePath, version string, status int) (err error) { @@ -685,18 +686,18 @@ func (db *DB) ReconcileSearch(ctx context.Context, modulePath, version string, s log.Debugf(ctx, "ReconcileSearch(%q): alternative or no good version; removed from search_documents and imports_unique", modulePath) return nil } - // Is the latest good version in search_documents? + // Is the latest good version in search_documents, or is there a longer module path? var x int switch err := tx.QueryRow(ctx, ` SELECT 1 FROM search_documents - WHERE module_path = $1 - AND version = $2 + WHERE (module_path = $1 AND version = $2) + OR module_path LIKE $1 || '/%' `, modulePath, lmv.GoodVersion).Scan(&x); err { case sql.ErrNoRows: break case nil: - log.Debugf(ctx, "ReconcileSearch(%q): good version %s found in search_documents; doing nothing", + log.Debugf(ctx, "ReconcileSearch(%q): good version %s or suffix module path found in search_documents; doing nothing", modulePath, lmv.GoodVersion) return nil default: |
