diff options
| author | Miguel Acero <acero@google.com> | 2020-08-12 14:26:00 -0400 |
|---|---|---|
| committer | Miguel Acero <acero@google.com> | 2020-08-17 18:38:08 +0000 |
| commit | 42d0b044bd63893571d2c23cdf6b84091e301ea5 (patch) | |
| tree | 089e8c5e4f152c82b68d2aa4d4b722f30b033164 /internal/postgres | |
| parent | 40b7ecf090467c9dd8c5cc065226d5e72333e519 (diff) | |
| download | go-x-pkgsite-42d0b044bd63893571d2c23cdf6b84091e301ea5.tar.xz | |
internal/postgres: populate module_version_states.incompatible field
This change adds support for inserting, sorting and updating
module_version_states.incompatible.
Updates golang/go#37714
Change-Id: I40b0831adef6e78beafee259e972cb0e4d4b90c4
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/248182
Run-TryBot: Julie Qiu <julie@golang.org>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/postgres')
| -rw-r--r-- | internal/postgres/requeue.go | 11 | ||||
| -rw-r--r-- | internal/postgres/requeue_test.go | 16 | ||||
| -rw-r--r-- | internal/postgres/versionstate.go | 21 |
3 files changed, 31 insertions, 17 deletions
diff --git a/internal/postgres/requeue.go b/internal/postgres/requeue.go index e9ce50d5..74cf91f5 100644 --- a/internal/postgres/requeue.go +++ b/internal/postgres/requeue.go @@ -84,11 +84,13 @@ func (db *DB) GetNextModulesToFetch(ctx context.Context, limit int) (_ []*intern query := fmt.Sprintf(nextModulesToProcessQuery, moduleVersionStateColumns) collect := func(rows *sql.Rows) error { - // Scan the last two columns separately; they are in the query only for sorting. + // Scan the last three columns separately; they are in the query only for sorting. scan := func(dests ...interface{}) error { - var latest bool - var npkg int - return rows.Scan(append(dests, &latest, &npkg)...) + var ( + incompatible, latest bool + npkg int + ) + return rows.Scan(append(dests, &incompatible, &latest, &npkg)...) } mv, err := scanModuleVersionState(scan) if err != nil { @@ -139,6 +141,7 @@ const nextModulesToProcessQuery = ` FROM module_version_states ORDER BY module_path, + incompatible, right(sort_version, 1) = '~' DESC, -- prefer release versions sort_version DESC ) diff --git a/internal/postgres/requeue_test.go b/internal/postgres/requeue_test.go index e683bb2b..17f3360c 100644 --- a/internal/postgres/requeue_test.go +++ b/internal/postgres/requeue_test.go @@ -30,8 +30,8 @@ func TestGetNextModulesToFetchAndUpdateModuleVersionStatesForReprocessing(t *tes numPackages, status int } var ( - latest = "v1.2.0" - notLatest = "v1.0.0" + latest = "v1.5.2" + notLatest = "v2.0.0+incompatible" big = 2000 small = 100 versions = []string{notLatest, latest} @@ -205,8 +205,9 @@ func TestGetNextModulesToFetchOnlyPicksUpStatus0AndStatusGreaterThan500(t *testi app_version, index_timestamp, status, - go_mod_path) - VALUES ($1, $2, $3, $4, $5, $6, $7)`, + go_mod_path, + incompatible) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, strconv.Itoa(status), "v1.0.0", version.ForSorting("v1.0.0"), @@ -214,6 +215,7 @@ func TestGetNextModulesToFetchOnlyPicksUpStatus0AndStatusGreaterThan500(t *testi time.Now(), status, strconv.Itoa(status), + false, ); err != nil { t.Fatal(err) } @@ -261,8 +263,9 @@ func TestGetNextModulesToFetchLargeModulesLimit(t *testing.T) { app_version, index_timestamp, status, - num_packages) - VALUES ($1, $2, $3, $4, $5, $6, $7)`, + num_packages, + incompatible) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, mp, v, version.ForSorting(v), @@ -270,6 +273,7 @@ func TestGetNextModulesToFetchLargeModulesLimit(t *testing.T) { time.Now(), status, numPackages, + isIncompatible(v), ); err != nil { t.Fatal(err) } diff --git a/internal/postgres/versionstate.go b/internal/postgres/versionstate.go index 064fd9cc..ad876d31 100644 --- a/internal/postgres/versionstate.go +++ b/internal/postgres/versionstate.go @@ -27,9 +27,9 @@ func (db *DB) InsertIndexVersions(ctx context.Context, versions []*internal.Inde var vals []interface{} for _, v := range versions { - vals = append(vals, v.Path, v.Version, version.ForSorting(v.Version), v.Timestamp, 0, "", "") + vals = append(vals, v.Path, v.Version, version.ForSorting(v.Version), v.Timestamp, 0, "", "", isIncompatible(v.Version)) } - cols := []string{"module_path", "version", "sort_version", "index_timestamp", "status", "error", "go_mod_path"} + cols := []string{"module_path", "version", "sort_version", "index_timestamp", "status", "error", "go_mod_path", "incompatible"} conflictAction := ` ON CONFLICT (module_path, version) @@ -89,8 +89,9 @@ func upsertModuleVersionState(ctx context.Context, db *database.DB, modulePath, status, go_mod_path, error, - num_packages) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + num_packages, + incompatible) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (module_path, version) DO UPDATE SET @@ -111,7 +112,7 @@ func upsertModuleVersionState(ctx context.Context, db *database.DB, modulePath, CURRENT_TIMESTAMP + INTERVAL '1 hour' END;`, modulePath, vers, version.ForSorting(vers), - appVersion, timestamp, status, goModPath, sqlErrorMsg, numPackages) + appVersion, timestamp, status, goModPath, sqlErrorMsg, numPackages, isIncompatible(vers)) if err != nil { return err } @@ -190,7 +191,8 @@ const moduleVersionStateColumns = ` next_processed_after, app_version, go_mod_path, - num_packages` + num_packages, + incompatible` // scanModuleVersionState constructs an *internal.ModuleModuleVersionState from the given // scanner. It expects columns to be in the order of moduleVersionStateColumns. @@ -279,7 +281,12 @@ func (db *DB) GetModuleVersionState(ctx context.Context, modulePath, version str AND version = $2;`, moduleVersionStateColumns) row := db.db.QueryRow(ctx, query, modulePath, version) - v, err := scanModuleVersionState(row.Scan) + // Ignore the incompatible column, it is only used for sorting. + scan := func(dests ...interface{}) error { + var incompatible bool + return row.Scan(append(dests, &incompatible)...) + } + v, err := scanModuleVersionState(scan) switch err { case nil: return v, nil |
