aboutsummaryrefslogtreecommitdiff
path: root/internal/postgres
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-04-12 18:21:05 -0400
committerJonathan Amsterdam <jba@google.com>2021-04-13 11:11:51 +0000
commitb6c709824c06f07477efdfa5bd2d5dc7ad76b0fa (patch)
treedf6e0ac0eca38b69f5f30fea349d0c72cc4190e2 /internal/postgres
parentb0d7b43aac22485c636bd144e0232b3f9b42453e (diff)
downloadgo-x-pkgsite-b6c709824c06f07477efdfa5bd2d5dc7ad76b0fa.tar.xz
many: remove "retractions" experiment
For golang/go#43265 Change-Id: Iac39814ce532adf5846bb768802a46ad7a77fa84 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/309609 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres')
-rw-r--r--internal/postgres/insert_module_test.go6
-rw-r--r--internal/postgres/unit.go24
-rw-r--r--internal/postgres/unit_test.go6
-rw-r--r--internal/postgres/version.go52
-rw-r--r--internal/postgres/version_test.go2
5 files changed, 38 insertions, 52 deletions
diff --git a/internal/postgres/insert_module_test.go b/internal/postgres/insert_module_test.go
index 291bb4c3..6478f160 100644
--- a/internal/postgres/insert_module_test.go
+++ b/internal/postgres/insert_module_test.go
@@ -37,6 +37,7 @@ func TestInsertModule(t *testing.T) {
for _, test := range []struct {
name string
module *internal.Module
+ goMod string
}{
{
name: "valid test",
@@ -74,15 +75,16 @@ func TestInsertModule(t *testing.T) {
m.DeprecationComment = "use v2"
return m
}(),
+ goMod: "module " + sample.ModulePath + " // Deprecated: use v2",
},
} {
t.Run(test.name, func(t *testing.T) {
testDB, release := acquire(t)
defer release()
- MustInsertModule(ctx, t, testDB, test.module)
+ MustInsertModuleGoMod(ctx, t, testDB, test.module, test.goMod)
// Test that insertion of duplicate primary key won't fail.
- MustInsertModule(ctx, t, testDB, test.module)
+ MustInsertModuleGoMod(ctx, t, testDB, test.module, test.goMod)
checkModule(ctx, t, testDB, test.module)
})
}
diff --git a/internal/postgres/unit.go b/internal/postgres/unit.go
index 5d48ebef..5cac3e2a 100644
--- a/internal/postgres/unit.go
+++ b/internal/postgres/unit.go
@@ -124,21 +124,19 @@ func (db *DB) getUnitMetaWithKnownLatestVersion(ctx context.Context, fullPath, m
}
um.Licenses = lics
- if experiment.IsActive(ctx, internal.ExperimentRetractions) {
- // If we don't have the latest version information, try to get it.
- // We can be here if there is really no info (in which case we are repeating
- // some work, but it's fast), or if we are ignoring the info (for instance,
- // if all versions were retracted).
- if lmv == nil {
- lmv, err = db.GetLatestModuleVersions(ctx, um.ModulePath)
- if err != nil {
- return nil, err
- }
- }
- if lmv != nil {
- lmv.PopulateModuleInfo(&um.ModuleInfo)
+ // If we don't have the latest version information, try to get it.
+ // We can be here if there is really no info (in which case we are repeating
+ // some work, but it's fast), or if we are ignoring the info (for instance,
+ // if all versions were retracted).
+ if lmv == nil {
+ lmv, err = db.GetLatestModuleVersions(ctx, um.ModulePath)
+ if err != nil {
+ return nil, err
}
}
+ if lmv != nil {
+ lmv.PopulateModuleInfo(&um.ModuleInfo)
+ }
return &um, nil
}
diff --git a/internal/postgres/unit_test.go b/internal/postgres/unit_test.go
index cf4f7ea4..37780f35 100644
--- a/internal/postgres/unit_test.go
+++ b/internal/postgres/unit_test.go
@@ -26,13 +26,11 @@ func TestGetUnitMeta(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testTimeout*2)
defer cancel()
- ctx = experiment.NewContext(ctx, internal.ExperimentRetractions)
t.Run("legacy", func(t *testing.T) {
testGetUnitMeta(t, ctx)
})
t.Run("latest", func(t *testing.T) {
- testGetUnitMeta(t, experiment.NewContext(ctx,
- internal.ExperimentRetractions, internal.ExperimentUnitMetaWithLatest))
+ testGetUnitMeta(t, experiment.NewContext(ctx, internal.ExperimentUnitMetaWithLatest))
})
}
@@ -295,7 +293,7 @@ func TestGetUnitMetaDiffs(t *testing.T) {
if got := modver(gotLegacy); got != test.wantLegacy {
t.Errorf("legacy: got %s, want %s", got, test.wantLegacy)
}
- gotLatest, err := testDB.GetUnitMeta(experiment.NewContext(ctx, internal.ExperimentRetractions, internal.ExperimentUnitMetaWithLatest),
+ gotLatest, err := testDB.GetUnitMeta(experiment.NewContext(ctx, internal.ExperimentUnitMetaWithLatest),
test.path, internal.UnknownModulePath, internal.LatestVersion)
if err != nil {
t.Fatal(err)
diff --git a/internal/postgres/version.go b/internal/postgres/version.go
index 8c2fffaa..5f9329c3 100644
--- a/internal/postgres/version.go
+++ b/internal/postgres/version.go
@@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"strings"
- "time"
"github.com/Masterminds/squirrel"
"github.com/lib/pq"
@@ -18,7 +17,6 @@ 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/version"
"golang.org/x/sync/errgroup"
@@ -115,17 +113,13 @@ func versionTypeExpr(vts []version.Type) string {
func populateLatestInfo(ctx context.Context, db *DB, mi *internal.ModuleInfo) (err error) {
defer derrors.WrapStack(&err, "populateLatestInfo(%q)", mi.ModulePath)
- if experiment.IsActive(ctx, internal.ExperimentRetractions) {
- // Get information about retractions an deprecations, and apply it.
- start := time.Now()
- lmv, err := db.GetLatestModuleVersions(ctx, mi.ModulePath)
- if err != nil {
- return err
- }
- if lmv != nil {
- lmv.PopulateModuleInfo(mi)
- }
- log.Debugf(ctx, "latest info fetched and applied in %dms", time.Since(start).Milliseconds())
+ // Get information about retractions an deprecations, and apply it.
+ lmv, err := db.GetLatestModuleVersions(ctx, mi.ModulePath)
+ if err != nil {
+ return err
+ }
+ if lmv != nil {
+ lmv.PopulateModuleInfo(mi)
}
return nil
}
@@ -133,27 +127,23 @@ func populateLatestInfo(ctx context.Context, db *DB, mi *internal.ModuleInfo) (e
func populateLatestInfos(ctx context.Context, db *DB, mis []*internal.ModuleInfo) (err error) {
defer derrors.WrapStack(&err, "populateLatestInfos(%d ModuleInfos)", len(mis))
- if experiment.IsActive(ctx, internal.ExperimentRetractions) {
- start := time.Now()
- // Collect the LatestModuleVersions for all modules in the list.
- lmvs := map[string]*internal.LatestModuleVersions{}
- for _, mi := range mis {
- if _, ok := lmvs[mi.ModulePath]; !ok {
- lmv, err := db.GetLatestModuleVersions(ctx, mi.ModulePath)
- if err != nil {
- return err
- }
- lmvs[mi.ModulePath] = lmv
+ // Collect the LatestModuleVersions for all modules in the list.
+ lmvs := map[string]*internal.LatestModuleVersions{}
+ for _, mi := range mis {
+ if _, ok := lmvs[mi.ModulePath]; !ok {
+ lmv, err := db.GetLatestModuleVersions(ctx, mi.ModulePath)
+ if err != nil {
+ return err
}
+ lmvs[mi.ModulePath] = lmv
}
- // Use the collected LatestModuleVersions to populate the ModuleInfos.
- for _, mi := range mis {
- lmv := lmvs[mi.ModulePath]
- if lmv != nil {
- lmv.PopulateModuleInfo(mi)
- }
+ }
+ // Use the collected LatestModuleVersions to populate the ModuleInfos.
+ for _, mi := range mis {
+ lmv := lmvs[mi.ModulePath]
+ if lmv != nil {
+ lmv.PopulateModuleInfo(mi)
}
- log.Debugf(ctx, "latest info fetched and applied in %dms", time.Since(start).Milliseconds())
}
return nil
}
diff --git a/internal/postgres/version_test.go b/internal/postgres/version_test.go
index 0f81dd47..7b09998b 100644
--- a/internal/postgres/version_test.go
+++ b/internal/postgres/version_test.go
@@ -12,7 +12,6 @@ import (
"github.com/google/go-cmp/cmp"
"golang.org/x/pkgsite/internal"
- "golang.org/x/pkgsite/internal/experiment"
"golang.org/x/pkgsite/internal/source"
"golang.org/x/pkgsite/internal/stdlib"
"golang.org/x/pkgsite/internal/testing/sample"
@@ -231,7 +230,6 @@ func TestGetVersions(t *testing.T) {
},
}
- ctx = experiment.NewContext(ctx, internal.ExperimentRetractions)
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
for _, w := range test.want {