diff options
| author | Julie Qiu <julie@golang.org> | 2020-10-16 16:35:13 -0400 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2020-10-16 21:35:09 +0000 |
| commit | a73eb822f072199f15ef893c0f5a9d8abb9b829d (patch) | |
| tree | 2dd4a8ccfe1ffdd802cf763501871d8370c449ed /internal/postgres/insert_module.go | |
| parent | 00f3c6132f6482ee9b906ad28a52caf4941b925d (diff) | |
| download | go-x-pkgsite-a73eb822f072199f15ef893c0f5a9d8abb9b829d.tar.xz | |
internal/postgres: stop writing to packages and imports tables
Data is no longer written to the packages and imports tables.
For golang/go#39629
Change-Id: I4dc284b514c7a8ed3222d870c59cc64d9fd71339
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/263199
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.go | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 794617c7..991f09dc 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -56,9 +56,6 @@ func (db *DB) InsertModule(ctx context.Context, m *internal.Module) (err error) if err := db.compareLicenses(ctx, m); err != nil { return err } - if err := db.comparePackages(ctx, m); err != nil { - return err - } if err := db.comparePaths(ctx, m); err != nil { return err } @@ -92,12 +89,7 @@ func (db *DB) saveModule(ctx context.Context, m *internal.Module) (err error) { if err := insertLicenses(ctx, tx, m, moduleID); err != nil { return err } - logMemory(ctx, "after insertLicenses") - if err := legacyInsertPackages(ctx, tx, m); err != nil { - return err - } - logMemory(ctx, "after insertPackages") if err := insertUnits(ctx, tx, m, moduleID); err != nil { return err @@ -240,102 +232,6 @@ func insertLicenses(ctx context.Context, db *database.DB, m *internal.Module, mo return nil } -func legacyInsertPackages(ctx context.Context, db *database.DB, m *internal.Module) (err error) { - ctx, span := trace.StartSpan(ctx, "insertPackages") - defer span.End() - defer derrors.Wrap(&err, "insertPackages(ctx, %q, %q)", m.ModulePath, m.Version) - - // Sort to ensure proper lock ordering, avoiding deadlocks. See - // b/141164828#comment8. The only deadlocks we've actually seen are on - // imports_unique, because they can occur when processing two versions of - // the same module, which happens regularly. But if we were ever to process - // the same module and version twice, we could see deadlocks in the other - // bulk inserts. - sort.Slice(m.LegacyPackages, func(i, j int) bool { - return m.LegacyPackages[i].Path < m.LegacyPackages[j].Path - }) - sort.Slice(m.Licenses, func(i, j int) bool { - return m.Licenses[i].FilePath < m.Licenses[j].FilePath - }) - for _, p := range m.LegacyPackages { - sort.Strings(p.Imports) - } - var pkgValues, importValues []interface{} - for _, p := range m.LegacyPackages { - if p.DocumentationHTML.String() == internal.StringFieldMissing { - return errors.New("saveModule: package missing DocumentationHTML") - } - var licenseTypes, licensePaths []string - for _, l := range p.Licenses { - if len(l.Types) == 0 { - // If a license file has no detected license types, we still need to - // record it as applicable to the package, because we want to fail - // closed (meaning if there is a LICENSE file containing unknown - // licenses, we assume them not to be permissive of redistribution.) - licenseTypes = append(licenseTypes, "") - licensePaths = append(licensePaths, l.FilePath) - } else { - for _, typ := range l.Types { - licenseTypes = append(licenseTypes, typ) - licensePaths = append(licensePaths, l.FilePath) - } - } - } - pkgValues = append(pkgValues, - p.Path, - p.Synopsis, - p.Name, - m.Version, - m.ModulePath, - p.V1Path, - p.IsRedistributable, - makeValidUnicode(p.DocumentationHTML.String()), - pq.Array(licenseTypes), - pq.Array(licensePaths), - p.GOOS, - p.GOARCH, - m.CommitTime, - ) - for _, i := range p.Imports { - importValues = append(importValues, p.Path, m.ModulePath, m.Version, i) - } - } - if len(pkgValues) > 0 { - uniqueCols := []string{"path", "module_path", "version"} - pkgCols := []string{ - "path", - "synopsis", - "name", - "version", - "module_path", - "v1_path", - "redistributable", - "documentation", - "license_types", - "license_paths", - "goos", - "goarch", - "commit_time", - } - if err := db.BulkUpsert(ctx, "packages", pkgCols, pkgValues, uniqueCols); err != nil { - return err - } - } - - if len(importValues) > 0 { - importCols := []string{ - "from_path", - "from_module_path", - "from_version", - "to_path", - } - if err := db.BulkUpsert(ctx, "imports", importCols, importValues, importCols); err != nil { - return err - } - } - return nil -} - // insertImportsUnique inserts and removes rows from the imports_unique table. It should only // be called if the given module's version is the latest. func insertImportsUnique(ctx context.Context, tx *database.DB, m *internal.Module) (err error) { @@ -646,36 +542,6 @@ func (db *DB) compareLicenses(ctx context.Context, m *internal.Module) (err erro return nil } -// comparePackages compares m.LegacyPackages with the existing packages for -// m.ModulePath and m.Version in the database. It returns an error if there -// are packages in the packages table that are not present in m.LegacyPackages. -func (db *DB) comparePackages(ctx context.Context, m *internal.Module) (err error) { - defer derrors.Wrap(&err, "comparePackages(ctx, %q, %q)", m.ModulePath, m.Version) - u, err := db.GetUnit(ctx, &internal.UnitMeta{ - ModulePath: m.ModulePath, - Path: m.ModulePath, - Version: m.Version, - IsRedistributable: m.IsRedistributable, - CommitTime: m.CommitTime, - }, internal.WithSubdirectories) - if err != nil { - if errors.Is(err, derrors.NotFound) { - return nil - } - return err - } - set := map[string]bool{} - for _, p := range m.LegacyPackages { - set[p.Path] = true - } - for _, p := range u.Subdirectories { - if _, ok := set[p.Path]; !ok { - return fmt.Errorf("expected package %q in module: %w", p.Path, derrors.DBModuleInsertInvalid) - } - } - return nil -} - // comparePaths compares m.Directories with the existing directories for // m.ModulePath and m.Version in the database. It returns an error if there // are paths in the paths table that are not present in m.Directories. |
