internal/postgres: replace units.path references with paths.path
Instead of reading from units.path, read from paths.path instead.
In a future CL, we will be deprecating units.path.
Change-Id: I71e06ae856dec5067d2284b409b74c44427d7e7a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/280160
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>
diff --git a/internal/postgres/search.go b/internal/postgres/search.go
index 7fbdd79..07db186 100644
--- a/internal/postgres/search.go
+++ b/internal/postgres/search.go
@@ -340,13 +340,16 @@
FROM
units u
INNER JOIN
- modules m
+ paths p
+ ON u.path_id = p.id
+ INNER JOIN
+ modules m
ON u.module_id = m.id
LEFT JOIN
- documentation d
+ documentation d
ON u.id = d.unit_id
WHERE
- (u.path, m.version, m.module_path) IN (%s)`, strings.Join(keys, ","))
+ (p.path, m.version, m.module_path) IN (%s)`, strings.Join(keys, ","))
collect := func(rows *sql.Rows) error {
var (
path, name, synopsis string
@@ -391,7 +394,7 @@
hll_leading_zeros
)
SELECT
- u.path,
+ p.path,
m.version,
m.module_path,
u.name,
@@ -412,6 +415,10 @@
FROM
units u
INNER JOIN
+ paths p
+ ON
+ p.id = u.path_id
+ INNER JOIN
modules m
ON
u.module_id = m.id
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go
index a64c172..06c30d5 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -93,7 +93,9 @@
"u.license_paths",
)
if requestedVersion != internal.LatestVersion {
- query = query.From("modules m").Join("units u on u.module_id = m.id").Where(squirrel.Eq{"u.path": fullPath})
+ query = query.From("modules m").
+ Join("units u on u.module_id = m.id").
+ Join("paths p ON p.id = u.path_id").Where(squirrel.Eq{"p.path": fullPath})
if requestedModulePath != internal.UnknownModulePath {
query = query.Where(squirrel.Eq{"m.module_path": requestedModulePath})
}