aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module.go
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2020-11-19 19:18:00 -0500
committerJulie Qiu <julie@golang.org>2020-11-20 21:55:36 +0000
commit5e6c29f65cc7929600ea2d0e4773ffa962f257be (patch)
treeadbde32a2a235fbae7fa3b6a9764965dd6d94fc4 /internal/postgres/insert_module.go
parent4d2f0315fa39052d667a82308a8e315c412e6321 (diff)
downloadgo-x-pkgsite-5e6c29f65cc7929600ea2d0e4773ffa962f257be.tar.xz
internal/postgres: use moduleID in getModuleLicenses
getModuleLicenses now accepts moduleID instead of module path and version as args. In a later CL, we will be dropping licenses.module_path and licenses.module_id. For golang/go#39629 Change-Id: I18c525c584fd181372ef6c01241a90c19cb28a96 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/271747 Trust: Julie Qiu <julie@golang.org> Run-TryBot: Julie Qiu <julie@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/postgres/insert_module.go')
-rw-r--r--internal/postgres/insert_module.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index 9e81744b..39065541 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -23,6 +23,7 @@ import (
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/database"
"golang.org/x/pkgsite/internal/derrors"
+ "golang.org/x/pkgsite/internal/licenses"
"golang.org/x/pkgsite/internal/log"
"golang.org/x/pkgsite/internal/stdlib"
"golang.org/x/pkgsite/internal/version"
@@ -51,9 +52,6 @@ func (db *DB) InsertModule(ctx context.Context, m *internal.Module) (err error)
// inserted. Rows that currently exist should not be missing from the
// new module. We want to be sure that we will overwrite every row that
// pertains to the module.
- if err := db.compareLicenses(ctx, m); err != nil {
- return err
- }
if err := db.comparePaths(ctx, m); err != nil {
return err
}
@@ -81,6 +79,13 @@ func (db *DB) saveModule(ctx context.Context, m *internal.Module) (err error) {
if err != nil {
return err
}
+ // Compare existing data from the database, and the module to be
+ // inserted. Rows that currently exist should not be missing from the
+ // new module. We want to be sure that we will overwrite every row that
+ // pertains to the module.
+ if err := db.compareLicenses(ctx, moduleID, m.Licenses); err != nil {
+ return err
+ }
if err := insertLicenses(ctx, tx, m, moduleID); err != nil {
return err
}
@@ -561,15 +566,15 @@ func validateModule(m *internal.Module) (err error) {
// compareLicenses compares m.Licenses with the existing licenses for
// m.ModulePath and m.Version in the database. It returns an error if there
// are licenses in the licenses table that are not present in m.Licenses.
-func (db *DB) compareLicenses(ctx context.Context, m *internal.Module) (err error) {
- defer derrors.Wrap(&err, "compareLicenses(ctx, %q, %q)", m.ModulePath, m.Version)
- dbLicenses, err := db.getModuleLicenses(ctx, m.ModulePath, m.Version)
+func (db *DB) compareLicenses(ctx context.Context, moduleID int, lics []*licenses.License) (err error) {
+ defer derrors.Wrap(&err, "compareLicenses(ctx, %d)", moduleID)
+ dbLicenses, err := db.getModuleLicenses(ctx, moduleID)
if err != nil {
return err
}
set := map[string]bool{}
- for _, l := range m.Licenses {
+ for _, l := range lics {
set[l.FilePath] = true
}
for _, l := range dbLicenses {