Skip to content

Commit b0b8b70

Browse files
committed
internal/postgres: add retraction/deprecation info to GetNestedModules
For golang/go#43265 Change-Id: I297856d635eda30d09e42a860f39e0cffc452464 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/295899 Trust: Jonathan Amsterdam <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent 62a311c commit b0b8b70

File tree

3 files changed

+40
-25
lines changed

3 files changed

+40
-25
lines changed

internal/postgres/details.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (db *DB) GetNestedModules(ctx context.Context, modulePath string) (_ []*int
6767
return nil, err
6868
}
6969

70+
if err := populateRawLatestInfo(ctx, db, modules); err != nil {
71+
return nil, err
72+
}
73+
7074
return modules, nil
7175
}
7276

internal/postgres/version.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,37 +93,48 @@ func getPathVersions(ctx context.Context, db *DB, path string, versionTypes ...v
9393
if err := db.db.RunQuery(ctx, query, collect, path); err != nil {
9494
return nil, err
9595
}
96+
if err := populateRawLatestInfo(ctx, db, versions); err != nil {
97+
return nil, err
98+
}
99+
return versions, nil
100+
}
101+
102+
// versionTypeExpr returns a comma-separated list of version types,
103+
// for use in a clause like "WHERE version_type IN (%s)"
104+
func versionTypeExpr(vts []version.Type) string {
105+
var vs []string
106+
for _, vt := range vts {
107+
vs = append(vs, fmt.Sprintf("'%s'", vt.String()))
108+
}
109+
return strings.Join(vs, ", ")
110+
}
111+
112+
func populateRawLatestInfo(ctx context.Context, db *DB, mis []*internal.ModuleInfo) (err error) {
113+
defer derrors.WrapStack(&err, "populateRawLatestInfo(%d ModuleInfos)", len(mis))
114+
96115
if experiment.IsActive(ctx, internal.ExperimentRetractions) {
97116
start := time.Now()
117+
// Collect the RawLatestInfos for all modules in the list.
98118
infos := map[string]*internal.RawLatestInfo{}
99-
for _, mi := range versions {
119+
for _, mi := range mis {
100120
if _, ok := infos[mi.ModulePath]; !ok {
101121
info, err := db.GetRawLatestInfo(ctx, mi.ModulePath)
102122
if err != nil {
103-
return nil, err
123+
return err
104124
}
105125
infos[mi.ModulePath] = info
106126
}
107127
}
108-
for _, mi := range versions {
128+
// Use the collected RawLatestInfos to populate the ModuleInfos.
129+
for _, mi := range mis {
109130
info := infos[mi.ModulePath]
110131
if info != nil {
111132
info.PopulateModuleInfo(mi)
112133
}
113134
}
114-
log.Debugf(ctx, "getPathVersions: raw latest info fetched and applied in %dms", time.Since(start).Milliseconds())
135+
log.Debugf(ctx, "raw latest info fetched and applied in %dms", time.Since(start).Milliseconds())
115136
}
116-
return versions, nil
117-
}
118-
119-
// versionTypeExpr returns a comma-separated list of version types,
120-
// for use in a clause like "WHERE version_type IN (%s)"
121-
func versionTypeExpr(vts []version.Type) string {
122-
var vs []string
123-
for _, vt := range vts {
124-
vs = append(vs, fmt.Sprintf("'%s'", vt.String()))
125-
}
126-
return strings.Join(vs, ", ")
137+
return nil
127138
}
128139

129140
// GetLatestInfo returns the latest information about the unit in the module.

internal/postgres/version_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,6 @@ func TestGetVersions(t *testing.T) {
250250
}
251251
}
252252

253-
func addRawLatest(ctx context.Context, t *testing.T, db *DB, modulePath, version, modFile string) {
254-
info, err := internal.NewRawLatestInfo(modulePath, version, []byte(modFile))
255-
if err != nil {
256-
t.Fatal(err)
257-
}
258-
if err := db.UpdateRawLatestInfo(ctx, info); err != nil {
259-
t.Fatal(err)
260-
}
261-
}
262-
263253
func TestGetLatestInfo(t *testing.T) {
264254
t.Parallel()
265255
testDB, release := acquire(t)
@@ -423,3 +413,13 @@ func TestShouldUpdateRawLatest(t *testing.T) {
423413
}
424414
}
425415
}
416+
417+
func addRawLatest(ctx context.Context, t *testing.T, db *DB, modulePath, version, modFile string) {
418+
info, err := internal.NewRawLatestInfo(modulePath, version, []byte(modFile))
419+
if err != nil {
420+
t.Fatal(err)
421+
}
422+
if err := db.UpdateRawLatestInfo(ctx, info); err != nil {
423+
t.Fatal(err)
424+
}
425+
}

0 commit comments

Comments
 (0)