diff options
| author | Jonathan Amsterdam <jba@google.com> | 2021-08-13 17:22:06 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2021-08-16 14:04:40 +0000 |
| commit | 01a72d71a6202e77ab9373fb6b5efee6d8588e8e (patch) | |
| tree | 03111b2b0a87434d9860e6ff17215d4fff686cff /internal/postgres/insert_module.go | |
| parent | f3045b5dce6b0d609f837238dfd815bd9804abce (diff) | |
| download | go-x-pkgsite-01a72d71a6202e77ab9373fb6b5efee6d8588e8e.tar.xz | |
internal/{worker,postgres}: check current module for alternative
When reconciling the contents of search_documents when we insert a
module, consider whether the version currently being processed is
alternative.
Previously, we didn't consider the current module because we only
checked the DB, and the status code for the current module hasn't been
inserted yet.
Change-Id: Ibeb02d7f56341119e2bf4f20f148b345b2b82828
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/341868
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/insert_module.go')
| -rw-r--r-- | internal/postgres/insert_module.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 253fe6e8..49fbda66 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -640,7 +640,9 @@ func insertReadmes(ctx context.Context, db *database.DB, // ReInsertLatestVersion checks that the latest good version matches the version // in search_documents. If it doesn't, it inserts the latest good version into // search_documents and imports_unique. -func (db *DB) ReInsertLatestVersion(ctx context.Context, modulePath string) (err error) { +// 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) ReInsertLatestVersion(ctx context.Context, modulePath, version string, status int) (err error) { defer derrors.WrapStack(&err, "ReInsertLatestVersion(%q)", modulePath) return db.db.Transact(ctx, sql.LevelRepeatableRead, func(tx *database.DB) error { @@ -657,9 +659,17 @@ func (db *DB) ReInsertLatestVersion(ctx context.Context, modulePath string) (err log.Debugf(ctx, "ReInsertLatestVersion(%q): no latest-version info", modulePath) return nil } - alt, err := isAlternativeModulePath(ctx, tx, modulePath) - if err != nil { - return err + // Determine if this is an alternative module. The + // isAlternativeModulePath function checks the DB, but at the time + // ReInsertLatestVersion is called, we haven't added the current module + // version's status to the DB, so we use the version and status + // arguments. + alt := version == lmv.CookedVersion && status == derrors.ToStatus(derrors.AlternativeModule) + if !alt { + alt, err = isAlternativeModulePath(ctx, tx, modulePath) + if err != nil { + return err + } } if alt || lmv.GoodVersion == "" { // A missing GoodVersion means that there are no good versions |
