aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/insert_module.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2020-09-29 12:59:27 -0400
committerJonathan Amsterdam <jba@google.com>2020-09-29 20:34:45 +0000
commit135895829587fb7ebda46246157eefcf9c1b1f1d (patch)
tree0bd11d870afdd5f1d075d6b2a4462b0a557c1137 /internal/postgres/insert_module.go
parent51d2285e5c68a7089403e1b6d2192a5d5787ac2f (diff)
downloadgo-x-pkgsite-135895829587fb7ebda46246157eefcf9c1b1f1d.tar.xz
internal/postgres: read and write source files
Write the encoded source files to the documentation.source column when a module is inserted, and read them back from getDocumentation. Change-Id: I9fc27c570c701522c9e00c6bf9270dbe51f8602d Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/258237 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres/insert_module.go')
-rw-r--r--internal/postgres/insert_module.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/internal/postgres/insert_module.go b/internal/postgres/insert_module.go
index e7ed5b1b..3191d085 100644
--- a/internal/postgres/insert_module.go
+++ b/internal/postgres/insert_module.go
@@ -24,6 +24,7 @@ import (
"golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/database"
"golang.org/x/pkgsite/internal/derrors"
+ "golang.org/x/pkgsite/internal/experiment"
"golang.org/x/pkgsite/internal/log"
"golang.org/x/pkgsite/internal/stdlib"
"golang.org/x/pkgsite/internal/version"
@@ -426,7 +427,12 @@ func insertUnits(ctx context.Context, db *database.DB, m *internal.Module, modul
pathToReadme[d.Path] = d.Readme
}
if d.Documentation != nil && d.Documentation.HTML.String() == internal.StringFieldMissing {
- return errors.New("saveModule: package missing Documentation.HTML")
+ return errors.New("insertUnits: package missing Documentation.HTML")
+ }
+ if experiment.IsActive(ctx, internal.ExperimentInsertPackageSource) {
+ if d.Documentation.Source == nil {
+ return errors.New("insertUnits: package missing source files")
+ }
}
pathToDoc[d.Path] = d.Documentation
if len(d.Imports) > 0 {
@@ -503,9 +509,15 @@ func insertUnits(ctx context.Context, db *database.DB, m *internal.Module, modul
}
id := pathToID[path]
docValues = append(docValues, id, doc.GOOS, doc.GOARCH, doc.Synopsis, makeValidUnicode(doc.HTML.String()))
+ if experiment.IsActive(ctx, internal.ExperimentInsertPackageSource) {
+ docValues = append(docValues, doc.Source)
+ }
}
uniqueCols := []string{"path_id", "goos", "goarch"}
docCols := append(uniqueCols, "synopsis", "html")
+ if experiment.IsActive(ctx, internal.ExperimentInsertPackageSource) {
+ docCols = append(docCols, "source")
+ }
if err := db.BulkUpsert(ctx, "documentation", docCols, docValues, uniqueCols); err != nil {
return err
}