aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-07-27 11:06:29 -0400
committerJonathan Amsterdam <jba@google.com>2021-07-27 16:42:59 +0000
commitbc1baae772b9e7e5edfa93d86e03f46068903ac9 (patch)
treeeffe8d598e0bd4df08094eb749d4d40d0304d5f0 /internal/postgres/insert_module.go
parente281c2aa071fb9bfec0a4260fc928bd6fc2ac5a9 (diff)
downloadgo-x-pkgsite-bc1baae772b9e7e5edfa93d86e03f46068903ac9.tar.xz
internal/postgres: delete old versions from search_documents on insert
When inserting the latest version of a module, delete all versions from search_documents before inserting the latest one. That will remove from search all packages that are not in the latest version. Change-Id: I58fe9a1e8974d7f3fbd1fa64212c4b0381895d09 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/337751 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>
Diffstat (limited to 'internal/postgres/insert_module.go')
-rw-r--r--internal/postgres/insert_module.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index 77114433..1ca03f9c 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -149,6 +149,13 @@ func (db *DB) saveModule(ctx context.Context, m *internal.Module, lmv *internal.
return err
}
+ // Delete this module from search_documents completely. Below we'll
+ // insert the packages from this module. This will effectively remove
+ // packages from older module versions that are not in the latest one.
+ if err := deleteModuleFromSearchDocuments(ctx, tx, m.ModulePath, nil); err != nil {
+ return err
+ }
+
// If the most recent version of this module has an alternative module
// path, then do not insert its packages into search_documents (and
// delete whatever is there). This happens when a module that initially
@@ -176,7 +183,7 @@ func (db *DB) saveModule(ctx context.Context, m *internal.Module, lmv *internal.
}
if alt {
log.Infof(ctx, "%s@%s: not inserting into search documents", m.ModulePath, m.Version)
- return deleteModuleFromSearchDocuments(ctx, tx, m.ModulePath, nil)
+ return nil
}
// Insert the module's packages into search_documents.
if err := upsertSearchDocuments(ctx, tx, m); err != nil {