aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres/unit_test.go
diff options
context:
space:
mode:
authorJulie Qiu <julie@golang.org>2020-10-19 21:22:14 -0400
committerJulie Qiu <julie@golang.org>2020-10-21 17:52:27 +0000
commite4e63e377b93205f2f089ff0b5ecdaa675461308 (patch)
tree7d608068c645f0483891a84b218d4cb7a958813f /internal/postgres/unit_test.go
parentb9e4da5ba0b3f8aaee7271d753b9ded29e71f716 (diff)
downloadgo-x-pkgsite-e4e63e377b93205f2f089ff0b5ecdaa675461308.tar.xz
internal/postgres: fetch unit page data with one query
Data for the unit page can now be fetched using a single query. Running this query in staging: golang.org/x/net/context: 27.394 ms (26.526 ms on second run) cloud.google.com/go/firestore: 77.537 ms (0.810 ms on second run) go.uber.org/zap: 1515.823 ms (13.242 ms on second run) net/http: 17694.337 ms (232.138 ms on second run) Change-Id: I337379551cd2b842212107ccd51edd961df5fd1e Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/263778 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>
Diffstat (limited to 'internal/postgres/unit_test.go')
-rw-r--r--internal/postgres/unit_test.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index bc3174fb..377c08f3 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -161,10 +161,13 @@ func TestGetUnit(t *testing.T) {
test.want.Name,
test.want.IsRedistributable,
)
- t.Run("unit-page", func(t *testing.T) {
+ t.Run("unit page with one query", func(t *testing.T) {
+ checkUnit(ctx, t, um, test.want, internal.ExperimentUnitPage, internal.ExperimentGetUnitWithOneQuery)
+ })
+ t.Run("unit page", func(t *testing.T) {
checkUnit(ctx, t, um, test.want, internal.ExperimentUnitPage)
})
- t.Run("no-experiments", func(t *testing.T) {
+ t.Run("no experiments", func(t *testing.T) {
test.want.Readme = &internal.Readme{
Filepath: sample.ReadmeFilePath,
Contents: sample.ReadmeContents,
@@ -188,8 +191,16 @@ func checkUnit(ctx context.Context, t *testing.T, um *internal.UnitMeta, want *i
cmpopts.IgnoreFields(licenses.Metadata{}, "Coverage"),
}
want.SourceInfo = um.SourceInfo
- if diff := cmp.Diff(want, got, opts...); diff != "" {
- t.Errorf("mismatch (-want, +got):\n%s", diff)
+ if experiment.IsActive(ctx, internal.ExperimentGetUnitWithOneQuery) {
+ want.NumImports = len(want.Imports)
+ opts = append(opts,
+ cmpopts.IgnoreFields(internal.Documentation{}, "HTML"),
+ cmpopts.IgnoreFields(internal.Unit{}, "Imports"),
+ cmpopts.IgnoreFields(internal.Unit{}, "LicenseContents"),
+ )
+ if diff := cmp.Diff(want, got, opts...); diff != "" {
+ t.Errorf("mismatch (-want, +got):\n%s", diff)
+ }
}
}