diff --git a/README.md b/README.md index b9e4f8ea..2dbc4649 100644 --- a/README.md +++ b/README.md @@ -84,3 +84,4 @@ Our guide to [contributing](CONTRIBUTING.md) outlines other aspects of how to co + diff --git a/internal/server/store.go b/internal/server/store.go index ee7cc64e..be91cecf 100644 --- a/internal/server/store.go +++ b/internal/server/store.go @@ -1476,12 +1476,16 @@ func (s *Store) ExecuteTransaction(transaction *Transaction) error { txn := s.database.NewTransaction(true) defer txn.Discard() + updateCountsPerDataset := make(map[string]int64) + for k, ds := range datasets { entities := transaction.DatasetEntities[k] - _, err := ds.StoreEntitiesWithTransaction(entities, txnTime, txn) + newItems, err := ds.StoreEntitiesWithTransaction(entities, txnTime, txn) if err != nil { return err } + + updateCountsPerDataset[k] = newItems } err := s.commitIDTxn() @@ -1494,5 +1498,18 @@ func (s *Store) ExecuteTransaction(transaction *Transaction) error { return err } + // update the txn counts + for k, v := range updateCountsPerDataset { + ds, ok := s.datasets.Load(k) + if !ok { + return errors.New("no dataset " + k) + } + + err = ds.(*Dataset).updateDataset(v, nil) + if err != nil { + return err + } + } + return nil } diff --git a/internal/server/store_test.go b/internal/server/store_test.go index 150f271c..5074659e 100644 --- a/internal/server/store_test.go +++ b/internal/server/store_test.go @@ -1798,12 +1798,57 @@ var _ = ginkgo.Describe("Scoped storage functions", func() { txn.DatasetEntities["people"] = entities txn.DatasetEntities["places"] = entities1 + // get counts before txn + dsInfo, err := store.NamespaceManager.GetDatasetNamespaceInfo() + + // check counts after txn + datasets := []string{"core.Dataset"} + dsEntity, err := store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, "people"), datasets) + Expect(err).To(BeNil()) + + if dsEntity != nil { + items, ok := dsEntity.Properties[dsInfo.ItemsKey] + Expect(ok).To(BeTrue()) + Expect(items).To(Equal(float64(5))) + } + + // check that the item counts have been updated for places + dsEntity, err = store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, "places"), datasets) + Expect(err).To(BeNil()) + + if dsEntity != nil { + items, ok := dsEntity.Properties[dsInfo.ItemsKey] + Expect(ok).To(BeTrue()) + Expect(items).To(Equal(float64(0))) + } + err = store.ExecuteTransaction(txn) Expect(err).To(BeNil()) people := dsm.GetDataset("people") peopleEntities, _ := people.GetEntities("", 100) Expect(len(peopleEntities.Entities)).To(Equal(6)) + + // check counts after txn + datasets = []string{"core.Dataset"} + dsEntity, err = store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, people.ID), datasets) + Expect(err).To(BeNil()) + + if dsEntity != nil { + items, ok := dsEntity.Properties[dsInfo.ItemsKey] + Expect(ok).To(BeTrue()) + Expect(items).To(Equal(float64(6))) + } + + // check that the item counts have been updated for places + dsEntity, err = store.GetEntity(fmt.Sprintf("%s:%s", dsInfo.DatasetPrefix, "places"), datasets) + Expect(err).To(BeNil()) + + if dsEntity != nil { + items, ok := dsEntity.Properties[dsInfo.ItemsKey] + Expect(ok).To(BeTrue()) + Expect(items).To(Equal(float64(1))) + } }) ginkgo.It("should find deleted version of entity with lookup", func() {