Skip to content

Commit eaf2377

Browse files
Revert "internal/postgres: utilize num_imports column in insert_module"
This reverts commit 28eed86. Reason for revert: migration takes too long Change-Id: I279e62342c79d2604cda4e7c9819bdaa8aac752c Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/721101 LUCI-TryBot-Result: Go LUCI <[email protected]> kokoro-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 9f629f0 commit eaf2377

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

internal/postgres/insert_module.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ func (pdb *DB) insertUnits(ctx context.Context, tx *database.DB,
409409
pq.Array(licenseTypes),
410410
pq.Array(licensePaths),
411411
pdb.bypassLicenseCheck || u.IsRedistributable,
412-
len(u.Imports),
413412
)
414413
if u.Readme != nil {
415414
pathToReadme[u.Path] = u.Readme
@@ -482,7 +481,6 @@ func insertUnits(ctx context.Context, db *database.DB, unitValues []any) (pathID
482481
"license_types",
483482
"license_paths",
484483
"redistributable",
485-
"num_imports",
486484
}
487485
uniqueUnitCols := []string{"path_id", "module_id"}
488486
returningUnitCols := []string{"id", "path_id"}

internal/postgres/insert_module_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func checkModule(ctx context.Context, t *testing.T, db *DB, want *internal.Modul
124124
}
125125
}
126126
wantu.Subdirectories = subdirectories
127-
wantu.NumImports = len(wantu.Imports)
128127
opts := cmp.Options{
129128
cmpopts.EquateEmpty(),
130129
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),

internal/postgres/unit.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,12 @@ func (db *DB) getUnitWithAllFields(ctx context.Context, um *internal.UnitMeta, b
474474
r.contents,
475475
d.synopsis,
476476
d.source,
477-
u.num_imports,
477+
COALESCE((
478+
SELECT COUNT(unit_id)
479+
FROM imports
480+
WHERE unit_id = u.id
481+
GROUP BY unit_id
482+
), 0) AS num_imports,
478483
COALESCE((
479484
SELECT imported_by_count
480485
FROM search_documents

0 commit comments

Comments
 (0)