internal/postgres: rename ReInsertLatestVersion

Rename to ReconcileSearch, which better describes its purpose.

Change-Id: Ib7562e6bf511ff1ad88129619feec110c81168d3
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/342169
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>
This commit is contained in:
Jonathan Amsterdam 2021-08-13 17:35:11 -04:00
Родитель 01a72d71a6
Коммит 46af8a773c
4 изменённых файлов: 17 добавлений и 16 удалений

Просмотреть файл

@ -637,13 +637,14 @@ func insertReadmes(ctx context.Context, db *database.DB,
return db.BulkUpsert(ctx, "readmes", readmeCols, readmeValues, []string{"unit_id"})
}
// 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.
// 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)
// 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 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) {
defer derrors.WrapStack(&err, "ReconcileSearch(%q)", modulePath)
return db.db.Transact(ctx, sql.LevelRepeatableRead, func(tx *database.DB) error {
// Hold the lock on the module path throughout.
@ -656,12 +657,12 @@ func (db *DB) ReInsertLatestVersion(ctx context.Context, modulePath, version str
return err
}
if lmv == nil {
log.Debugf(ctx, "ReInsertLatestVersion(%q): no latest-version info", modulePath)
log.Debugf(ctx, "ReconcileSearch(%q): no latest-version info", modulePath)
return nil
}
// 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
// ReconcileSearch 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)
@ -681,7 +682,7 @@ func (db *DB) ReInsertLatestVersion(ctx context.Context, modulePath, version str
if err := deleteModuleFromImportsUnique(ctx, tx, modulePath); err != nil {
return err
}
log.Debugf(ctx, "ReInsertLatestVersion(%q): alternative or no good version; removed from search_documents and imports_unique", modulePath)
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?
@ -695,7 +696,7 @@ func (db *DB) ReInsertLatestVersion(ctx context.Context, modulePath, version str
case sql.ErrNoRows:
break
case nil:
log.Debugf(ctx, "ReInsertLatestVersion(%q): good version %s found in search_documents; doing nothing",
log.Debugf(ctx, "ReconcileSearch(%q): good version %s found in search_documents; doing nothing",
modulePath, lmv.GoodVersion)
return nil
default:
@ -755,7 +756,7 @@ func (db *DB) ReInsertLatestVersion(ctx context.Context, modulePath, version str
return err
}
log.Debugf(ctx, "ReInsertLatestVersion(%q): re-inserted at latest good version %s", modulePath, lmv.GoodVersion)
log.Debugf(ctx, "ReconcileSearch(%q): re-inserted at latest good version %s", modulePath, lmv.GoodVersion)
return nil
})
}

Просмотреть файл

@ -615,7 +615,7 @@ func TestIsAlternativeModulePath(t *testing.T) {
}
}
func TestReInsertLatestVersion(t *testing.T) {
func TestReconcileSearch(t *testing.T) {
testDB, release := acquire(t)
defer release()
ctx := context.Background()
@ -640,7 +640,7 @@ func TestReInsertLatestVersion(t *testing.T) {
}); err != nil {
t.Fatal(err)
}
if err := testDB.ReInsertLatestVersion(ctx, modulePath, version, status); err != nil {
if err := testDB.ReconcileSearch(ctx, modulePath, version, status); err != nil {
t.Fatal(err)
}
}

Просмотреть файл

@ -749,7 +749,7 @@ func UpsertSearchDocument(ctx context.Context, ddb *database.DB, args UpsertSear
defer derrors.WrapStack(&err, "DB.UpsertSearchDocument(ctx, ddb, %q, %q)", args.PackagePath, args.ModulePath)
// Only summarize the README if the package and module have the same path.
// If this changes, fix DB.ReInsertLatestVersion.
// If this changes, fix DB.ReconcileSearch.
if args.PackagePath != args.ModulePath {
args.ReadmeFilePath = ""
args.ReadmeContents = ""

Просмотреть файл

@ -117,7 +117,7 @@ func (f *Fetcher) FetchAndUpdateState(ctx context.Context, modulePath, requested
// Make sure the latest version of the module is the one in search_documents
// and imports_unique.
if err := f.DB.ReInsertLatestVersion(ctx, modulePath, ft.ResolvedVersion, ft.Status); err != nil {
if err := f.DB.ReconcileSearch(ctx, modulePath, ft.ResolvedVersion, ft.Status); err != nil {
log.Error(ctx, err)
if ft.Status != http.StatusInternalServerError {
ft.Error = err