internal: add experiment do-not-insert-new-documentation
We want to rename new_documentation to documentation, and drop the
current documentation table.
INSERTs into new_documentation are added as a first step.
Change-Id: I2f4038890436946b2c140c108faa4740e16abe4e
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/310375
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/experiment.go b/internal/experiment.go
index 99939e6..913f81e 100644
--- a/internal/experiment.go
+++ b/internal/experiment.go
@@ -6,17 +6,19 @@
package internal
const (
- ExperimentInsertSymbols = "insert-symbols"
- ExperimentSymbolHistoryVersionsPage = "symbol-history-versions-page"
- ExperimentSymbolHistoryMainPage = "symbol-history-main-page"
+ ExperimentDoNotInsertNewDocumentation = "do-not-insert-new-documentation"
+ ExperimentInsertSymbols = "insert-symbols"
+ ExperimentSymbolHistoryVersionsPage = "symbol-history-versions-page"
+ ExperimentSymbolHistoryMainPage = "symbol-history-main-page"
)
// Experiments represents all of the active experiments in the codebase and
// a description of each experiment.
var Experiments = map[string]string{
- ExperimentInsertSymbols: "Insert data into symbols, package_symbols, and documentation_symbols.",
- ExperimentSymbolHistoryVersionsPage: "Show package API history on the versions page.",
- ExperimentSymbolHistoryMainPage: "Show package API history on the main unit page.",
+ ExperimentDoNotInsertNewDocumentation: "Do not insert into the new_documentation table.",
+ ExperimentInsertSymbols: "Insert data into symbols, package_symbols, and documentation_symbols.",
+ ExperimentSymbolHistoryVersionsPage: "Show package API history on the versions page.",
+ ExperimentSymbolHistoryMainPage: "Show package API history on the main unit page.",
}
// Experiment holds data associated with an experimental feature for frontend
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index 732b64b..0b773fa 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -536,10 +536,18 @@
uniqueCols := []string{"unit_id", "goos", "goarch"}
docCols := append(uniqueCols, "synopsis", "source")
- if err := db.CopyUpsert(ctx, "documentation", docCols, database.CopyFromChan(generateRows()), uniqueCols, ""); err != nil {
+ if experiment.IsActive(ctx, internal.ExperimentDoNotInsertNewDocumentation) {
+ return db.CopyUpsert(ctx, "documentation",
+ docCols, database.CopyFromChan(generateRows()), uniqueCols, "id")
+ }
+
+ // These lines can be deleted once new_documentation is renamed to documentation.
+ if err := db.CopyUpsert(ctx, "documentation",
+ docCols, database.CopyFromChan(generateRows()), uniqueCols, ""); err != nil {
return err
}
- return db.CopyUpsert(ctx, "new_documentation", docCols, database.CopyFromChan(generateRows()), uniqueCols, "id")
+ return db.CopyUpsert(ctx, "new_documentation",
+ docCols, database.CopyFromChan(generateRows()), uniqueCols, "id")
}
// getDocIDsForPath returns a map of the unit path to documentation.id to
diff --git a/internal/postgres/symbol.go b/internal/postgres/symbol.go
index 4700db1..631f899 100644
--- a/internal/postgres/symbol.go
+++ b/internal/postgres/symbol.go
@@ -305,7 +305,11 @@
// Fetch all symbols for the unit. Order by symbol_type "Type" first, so
// that when we collect the children the structs for these symbols will
// already be created.
- query := `
+ doctable := "new_documentation"
+ if experiment.IsActive(ctx, internal.ExperimentDoNotInsertNewDocumentation) {
+ doctable = "documentation"
+ }
+ query := fmt.Sprintf(`
SELECT
s1.name AS symbol_name,
s2.name AS parent_symbol_name,
@@ -315,12 +319,12 @@
d.goos,
d.goarch
FROM documentation_symbols ds
- INNER JOIN new_documentation d ON d.id = ds.documentation_id
+ INNER JOIN %s d ON d.id = ds.documentation_id
INNER JOIN package_symbols ps ON ds.package_symbol_id = ps.id
INNER JOIN symbol_names s1 ON ps.symbol_name_id = s1.id
INNER JOIN symbol_names s2 ON ps.parent_symbol_name_id = s2.id
WHERE d.unit_id = $1
- ORDER BY CASE WHEN ps.type='Type' THEN 0 ELSE 1 END;`
+ ORDER BY CASE WHEN ps.type='Type' THEN 0 ELSE 1 END;`, doctable)
// buildToSymbols contains all of the symbols for this unit, grouped by
// build context.
buildToSymbols := map[internal.BuildContext][]*internal.Symbol{}
diff --git a/internal/postgres/symbol_history.go b/internal/postgres/symbol_history.go
index b40b388..920f04c 100644
--- a/internal/postgres/symbol_history.go
+++ b/internal/postgres/symbol_history.go
@@ -11,13 +11,19 @@
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/derrors"
+ "golang.org/x/pkgsite/internal/experiment"
)
// GetPackageSymbols returns all of the symbols for a given package path and module path.
func (db *DB) GetPackageSymbols(ctx context.Context, packagePath, modulePath string,
) (_ map[string]map[string]*internal.UnitSymbol, err error) {
defer derrors.Wrap(&err, "GetPackageSymbols(ctx, db, %q, %q)", packagePath, modulePath)
- query := `
+
+ doctable := "new_documentation"
+ if experiment.IsActive(ctx, internal.ExperimentDoNotInsertNewDocumentation) {
+ doctable = "documentation"
+ }
+ query := fmt.Sprintf(`
SELECT
s1.name AS symbol_name,
s2.name AS parent_symbol_name,
@@ -29,7 +35,7 @@
d.goarch
FROM modules m
INNER JOIN units u ON u.module_id = m.id
- INNER JOIN new_documentation d ON d.unit_id = u.id
+ INNER JOIN %s d ON d.unit_id = u.id
INNER JOIN documentation_symbols ds ON ds.documentation_id = d.id
INNER JOIN package_symbols ps ON ps.id = ds.package_symbol_id
INNER JOIN paths p1 ON u.path_id = p1.id
@@ -42,7 +48,7 @@
AND m.version_type = 'release'
ORDER BY
CASE WHEN ps.type='Type' THEN 0 ELSE 1 END,
- symbol_name;`
+ symbol_name;`, doctable)
// versionToNameToUnitSymbol contains all of the types for this unit,
// grouped by name and build context. This is used to keep track of the