diff options
| author | Julie Qiu <julie@golang.org> | 2021-01-07 09:49:04 -0500 |
|---|---|---|
| committer | Julie Qiu <julie@golang.org> | 2021-01-12 15:19:11 +0000 |
| commit | eb28c607e62e4589bff032ef9b01c56a4aa2e82e (patch) | |
| tree | 8a77e98608d7b729ea3899bf668a9eb28eae3278 /internal/postgres/insert_module.go | |
| parent | ac8f389d0946b7ba75a3cc252f19f1b21a145a35 (diff) | |
| download | go-x-pkgsite-eb28c607e62e4589bff032ef9b01c56a4aa2e82e.tar.xz | |
internal/postgres: stop writing to units.path
In a future CL, we will be deprecating units.path.
Change-Id: I17f8a3b1499b906f36567271c652a65b3bebfc57
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/282116
Trust: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'internal/postgres/insert_module.go')
| -rw-r--r-- | internal/postgres/insert_module.go | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go index 03c9b551..e26c2517 100644 --- a/internal/postgres/insert_module.go +++ b/internal/postgres/insert_module.go @@ -281,11 +281,12 @@ func (pdb *DB) insertUnits(ctx context.Context, db *database.DB, m *internal.Mod } var ( - unitValues []interface{} paths []string + unitValues []interface{} pathToReadme = map[string]*internal.Readme{} pathToDoc = map[string]*internal.Documentation{} pathToImports = map[string][]string{} + pathIDToPath = map[int]string{} ) for _, u := range m.Units { var licenseTypes, licensePaths []string @@ -305,9 +306,10 @@ func (pdb *DB) insertUnits(ctx context.Context, db *database.DB, m *internal.Mod } } v1path := internal.V1Path(u.Path, m.ModulePath) + pathID := pathToID[u.Path] + pathIDToPath[pathID] = u.Path unitValues = append(unitValues, - u.Path, - pathToID[u.Path], + pathID, moduleID, pathToID[v1path], v1path, @@ -328,10 +330,14 @@ func (pdb *DB) insertUnits(ctx context.Context, db *database.DB, m *internal.Mod } paths = append(paths, u.Path) } - pathToUnitID, err := insertUnits(ctx, db, unitValues) + pathIDToUnitID, err := insertUnits(ctx, db, unitValues) if err != nil { return err } + pathToUnitID := map[string]int{} + for pid, uid := range pathIDToUnitID { + pathToUnitID[pathIDToPath[pid]] = uid + } if err := insertReadmes(ctx, db, paths, pathToUnitID, pathToReadme); err != nil { return err } @@ -393,12 +399,11 @@ func insertPaths(ctx context.Context, db *database.DB, m *internal.Module) (path return pathToID, nil } -func insertUnits(ctx context.Context, db *database.DB, unitValues []interface{}) (pathToUnitID map[string]int, err error) { +func insertUnits(ctx context.Context, db *database.DB, unitValues []interface{}) (pathIDToUnitID map[int]int, err error) { defer derrors.Wrap(&err, "insertUnits") // Insert data into the units table. unitCols := []string{ - "path", "path_id", "module_id", "v1path_id", @@ -408,25 +413,22 @@ func insertUnits(ctx context.Context, db *database.DB, unitValues []interface{}) "license_paths", "redistributable", } - uniqueUnitCols := []string{"path", "module_id"} - returningUnitCols := []string{"id", "path"} + uniqueUnitCols := []string{"path_id", "module_id"} + returningUnitCols := []string{"id", "path_id"} - pathToUnitID = map[string]int{} + pathIDToUnitID = map[int]int{} if err := db.BulkUpsertReturning(ctx, "units", unitCols, unitValues, uniqueUnitCols, returningUnitCols, func(rows *sql.Rows) error { - var ( - unitID int - path string - ) - if err := rows.Scan(&unitID, &path); err != nil { + var pathID, unitID int + if err := rows.Scan(&unitID, &pathID); err != nil { return err } - pathToUnitID[path] = unitID + pathIDToUnitID[pathID] = unitID return nil }); err != nil { return nil, err } - return pathToUnitID, nil + return pathIDToUnitID, nil } func insertDoc(ctx context.Context, db *database.DB, |
