internal/worker: rename UpdateRecord to CommitUpdateRecord
Change-Id: I3428c15f1596454f6d09030d39ec2e9253d14438
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/368295
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/worker/store/fire_store.go b/internal/worker/store/fire_store.go
index d1266a4..98940de 100644
--- a/internal/worker/store/fire_store.go
+++ b/internal/worker/store/fire_store.go
@@ -23,7 +23,9 @@
//
// In this layout, there is a single top-level collection called Namespaces,
// with documents for each development environment. Within each namespace, there
-// are two collections: CVEs for CVERecords, and Updates for UpdateRecords.
+// are some collections:
+// - CVEs for CVERecords
+// - CommitUpdates for CommitUpdateRecords
type FireStore struct {
namespace string
client *firestore.Client
@@ -57,10 +59,10 @@
}, nil
}
-// CreateUpdateRecord implements Store.CreateUpdateRecord.
+// CreateCommitUpdateRecord implements Store.CreateCommitUpdateRecord.
// On successful return, r.ID is set to the record's ID.
-func (fs *FireStore) CreateUpdateRecord(ctx context.Context, r *UpdateRecord) (err error) {
- defer derrors.Wrap(&err, "CreateUpdateRecord()")
+func (fs *FireStore) CreateCommitUpdateRecord(ctx context.Context, r *CommitUpdateRecord) (err error) {
+ defer derrors.Wrap(&err, "CreateCommitUpdateRecord()")
docref := fs.nsDoc.Collection(updateCollection).NewDoc()
if _, err := docref.Create(ctx, r); err != nil {
@@ -70,9 +72,9 @@
return nil
}
-// SetUpdateRecord implements Store.SetUpdateRecord.
-func (fs *FireStore) SetUpdateRecord(ctx context.Context, r *UpdateRecord) (err error) {
- defer derrors.Wrap(&err, "SetUpdateRecord(%q)", r.ID)
+// SetCommitUpdateRecord implements Store.SetCommitUpdateRecord.
+func (fs *FireStore) SetCommitUpdateRecord(ctx context.Context, r *CommitUpdateRecord) (err error) {
+ defer derrors.Wrap(&err, "SetCommitUpdateRecord(%q)", r.ID)
if r.ID == "" {
return errors.New("missing ID")
@@ -81,9 +83,9 @@
return err
}
-// ListUpdateRecords implements Store.ListUpdateRecords.
-func (fs *FireStore) ListUpdateRecords(ctx context.Context) ([]*UpdateRecord, error) {
- var urs []*UpdateRecord
+// ListCommitUpdateRecords implements Store.ListCommitUpdateRecords.
+func (fs *FireStore) ListCommitUpdateRecords(ctx context.Context) ([]*CommitUpdateRecord, error) {
+ var urs []*CommitUpdateRecord
iter := fs.nsDoc.Collection(updateCollection).Documents(ctx)
for {
docsnap, err := iter.Next()
@@ -93,7 +95,7 @@
if err != nil {
return nil, err
}
- var ur UpdateRecord
+ var ur CommitUpdateRecord
if err := docsnap.DataTo(&ur); err != nil {
return nil, err
}
diff --git a/internal/worker/store/mem_store.go b/internal/worker/store/mem_store.go
index be04fa0..62282f1 100644
--- a/internal/worker/store/mem_store.go
+++ b/internal/worker/store/mem_store.go
@@ -18,7 +18,7 @@
type MemStore struct {
mu sync.Mutex
cveRecords map[string]*CVERecord
- updateRecords map[string]*UpdateRecord
+ updateRecords map[string]*CommitUpdateRecord
}
// NewMemStore creates a new, empty MemStore.
@@ -31,7 +31,7 @@
// Clear removes all data from the MemStore.
func (ms *MemStore) Clear(context.Context) error {
ms.cveRecords = map[string]*CVERecord{}
- ms.updateRecords = map[string]*UpdateRecord{}
+ ms.updateRecords = map[string]*CommitUpdateRecord{}
return nil
}
@@ -40,20 +40,20 @@
return ms.cveRecords
}
-// CreateUpdateRecord implements Store.CreateUpdateRecord.
-func (ms *MemStore) CreateUpdateRecord(ctx context.Context, r *UpdateRecord) error {
+// CreateCommitUpdateRecord implements Store.CreateCommitUpdateRecord.
+func (ms *MemStore) CreateCommitUpdateRecord(ctx context.Context, r *CommitUpdateRecord) error {
r.ID = fmt.Sprint(rand.Uint32())
if ms.updateRecords[r.ID] != nil {
panic("duplicate ID")
}
r.UpdatedAt = time.Now()
- return ms.SetUpdateRecord(ctx, r)
+ return ms.SetCommitUpdateRecord(ctx, r)
}
-// SetUpdateRecord implements Store.SetUpdateRecord.
-func (ms *MemStore) SetUpdateRecord(_ context.Context, r *UpdateRecord) error {
+// SetCommitUpdateRecord implements Store.SetCommitUpdateRecord.
+func (ms *MemStore) SetCommitUpdateRecord(_ context.Context, r *CommitUpdateRecord) error {
if r.ID == "" {
- return errors.New("SetUpdateRecord: need ID")
+ return errors.New("SetCommitUpdateRecord: need ID")
}
c := *r
c.UpdatedAt = time.Now()
@@ -61,9 +61,9 @@
return nil
}
-// ListUpdateRecords implements Store.ListUpdateRecords.
-func (ms *MemStore) ListUpdateRecords(context.Context) ([]*UpdateRecord, error) {
- var urs []*UpdateRecord
+// ListCommitUpdateRecords implements Store.ListCommitUpdateRecords.
+func (ms *MemStore) ListCommitUpdateRecords(context.Context) ([]*CommitUpdateRecord, error) {
+ var urs []*CommitUpdateRecord
for _, ur := range ms.updateRecords {
urs = append(urs, ur)
}
diff --git a/internal/worker/store/store.go b/internal/worker/store/store.go
index 776643d..4ab8556 100644
--- a/internal/worker/store/store.go
+++ b/internal/worker/store/store.go
@@ -93,9 +93,9 @@
}
}
-// An UpdateRecord describes a single update operation, which reconciles
+// A CommitUpdateRecord describes a single update operation, which reconciles
// a commit in the CVE list repo with the DB state.
-type UpdateRecord struct {
+type CommitUpdateRecord struct {
// The ID of this record in the DB. Needed to modify the record.
ID string
// When the update started and completed. If EndedAt is zero,
@@ -120,18 +120,18 @@
// A Store is a storage system for the CVE database.
type Store interface {
- // CreateUpdateRecord creates a new UpdateRecord. It should be called at the start
- // of an update. On successful return, the UpdateRecord's ID field will be
+ // CreateCommitUpdateRecord creates a new CommitUpdateRecord. It should be called at the start
+ // of an update. On successful return, the CommitUpdateRecord's ID field will be
// set to a new, unique ID.
- CreateUpdateRecord(context.Context, *UpdateRecord) error
+ CreateCommitUpdateRecord(context.Context, *CommitUpdateRecord) error
- // SetUpdateRecord modifies the UpdateRecord. Use the same record passed to
- // CreateUpdateRecord, because it will have the correct ID.
- SetUpdateRecord(context.Context, *UpdateRecord) error
+ // SetCommitUpdateRecord modifies the CommitUpdateRecord. Use the same record passed to
+ // CreateCommitUpdateRecord, because it will have the correct ID.
+ SetCommitUpdateRecord(context.Context, *CommitUpdateRecord) error
- // ListUpdateRecords returns all the UpdateRecords in the store, from most to
+ // ListCommitUpdateRecords returns all the CommitUpdateRecords in the store, from most to
// least recent.
- ListUpdateRecords(context.Context) ([]*UpdateRecord, error)
+ ListCommitUpdateRecords(context.Context) ([]*CommitUpdateRecord, error)
// RunTransaction runs the function in a transaction.
RunTransaction(context.Context, func(context.Context, Transaction) error) error
diff --git a/internal/worker/store/store_test.go b/internal/worker/store/store_test.go
index 8bf93cd..cc1dfb6 100644
--- a/internal/worker/store/store_test.go
+++ b/internal/worker/store/store_test.go
@@ -34,31 +34,31 @@
ctx := context.Background()
start := time.Date(2021, time.September, 1, 0, 0, 0, 0, time.Local)
- u1 := &UpdateRecord{
+ u1 := &CommitUpdateRecord{
StartedAt: start,
CommitHash: "abc",
NumTotal: 100,
}
- must(t, s.CreateUpdateRecord(ctx, u1))
+ must(t, s.CreateCommitUpdateRecord(ctx, u1))
u1.EndedAt = u1.StartedAt.Add(10 * time.Minute)
u1.NumAdded = 100
- must(t, s.SetUpdateRecord(ctx, u1))
- u2 := &UpdateRecord{
+ must(t, s.SetCommitUpdateRecord(ctx, u1))
+ u2 := &CommitUpdateRecord{
StartedAt: start.Add(time.Hour),
CommitHash: "def",
NumTotal: 80,
}
- must(t, s.CreateUpdateRecord(ctx, u2))
+ must(t, s.CreateCommitUpdateRecord(ctx, u2))
u2.EndedAt = u2.StartedAt.Add(8 * time.Minute)
u2.NumAdded = 40
u2.NumModified = 40
- must(t, s.SetUpdateRecord(ctx, u2))
- got, err := s.ListUpdateRecords(ctx)
+ must(t, s.SetCommitUpdateRecord(ctx, u2))
+ got, err := s.ListCommitUpdateRecords(ctx)
if err != nil {
t.Fatal(err)
}
- want := []*UpdateRecord{u2, u1}
- diff(t, want, got, cmpopts.IgnoreFields(UpdateRecord{}, "UpdatedAt"))
+ want := []*CommitUpdateRecord{u2, u1}
+ diff(t, want, got, cmpopts.IgnoreFields(CommitUpdateRecord{}, "UpdatedAt"))
for _, g := range got {
if g.UpdatedAt.IsZero() {
t.Error("zero UpdatedAt field")
diff --git a/internal/worker/update.go b/internal/worker/update.go
index 61f82e8..a89b9a8 100644
--- a/internal/worker/update.go
+++ b/internal/worker/update.go
@@ -59,13 +59,13 @@
if err != nil {
return err
}
- // Create a new UpdateRecord to describe this run of doUpdate.
- ur := &store.UpdateRecord{
+ // Create a new CommitUpdateRecord to describe this run of doUpdate.
+ ur := &store.CommitUpdateRecord{
StartedAt: time.Now(),
CommitHash: commitHash.String(),
NumTotal: len(files),
}
- if err := st.CreateUpdateRecord(ctx, ur); err != nil {
+ if err := st.CreateCommitUpdateRecord(ctx, ur); err != nil {
return err
}
@@ -82,10 +82,10 @@
}
numAdds, numMods, err := updateBatch(ctx, files[i:j], st, repo, commitHash, needsIssue)
- // Change the UpdateRecord in the Store to reflect the results of the transaction.
+ // Change the CommitUpdateRecord in the Store to reflect the results of the transaction.
if err != nil {
ur.Error = err.Error()
- if err2 := st.SetUpdateRecord(ctx, ur); err2 != nil {
+ if err2 := st.SetCommitUpdateRecord(ctx, ur); err2 != nil {
return fmt.Errorf("update failed with %w, could not set update record: %v", err, err2)
}
return err
@@ -95,13 +95,13 @@
// RunTransaction, because that function may be executed multiple times.
ur.NumAdded += numAdds
ur.NumModified += numMods
- if err := st.SetUpdateRecord(ctx, ur); err != nil {
+ if err := st.SetCommitUpdateRecord(ctx, ur); err != nil {
return err
}
} // end loop
ur.EndedAt = time.Now()
- return st.SetUpdateRecord(ctx, ur)
+ return st.SetCommitUpdateRecord(ctx, ur)
}
func updateBatch(ctx context.Context, batch []repoFile, st store.Store, repo *git.Repository, commitHash plumbing.Hash, needsIssue triageFunc) (numAdds, numMods int, err error) {