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>
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index 49fbda6..073ab41 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -637,13 +637,14 @@
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 @@
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 @@
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 @@
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 @@
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
})
}
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 2f5fbac..42510ee 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -615,7 +615,7 @@
}
}
-func TestReInsertLatestVersion(t *testing.T) {
+func TestReconcileSearch(t *testing.T) {
testDB, release := acquire(t)
defer release()
ctx := context.Background()
@@ -640,7 +640,7 @@
}); 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)
}
}
diff --git a/internal/postgres/search.go b/internal/postgres/search.go
index 0b70397..d6cc887 100644
--- a/internal/postgres/search.go
+++ b/internal/postgres/search.go
@@ -749,7 +749,7 @@
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 = ""
diff --git a/internal/worker/fetch.go b/internal/worker/fetch.go
index 8d74be0..3dc44d1 100644
--- a/internal/worker/fetch.go
+++ b/internal/worker/fetch.go
@@ -117,7 +117,7 @@
// 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