Skip to content

Commit

Permalink
use context.Background instead of context.TODO
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 297370524
Change-Id: I3f5440197d9734c231f61cbe7350bb5330238655
  • Loading branch information
ghasemloo authored and copybara-github committed Feb 26, 2020
1 parent 28d1748 commit bf618f5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/dsstore/data_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *DatastoreStorage) Info() map[string]string {
func (s *DatastoreStorage) Exists(datatype, realm, user, id string, rev int64) (bool, error) {
k := datastore.NameKey(entityKind, s.entityKey(datatype, realm, user, id, rev), nil)
e := new(DatastoreEntity)
err := s.client.Get(context.TODO, k, e)
err := s.client.Get(context.Background() /* TODO: pass ctx from request */, k, e)
if err == nil {
return true, nil
} else if err == datastore.ErrNoSuchEntity {
Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *DatastoreStorage) MultiReadTx(datatype, realm, user string, filters [][
offset = 0
}

it := s.client.Run(context.TODO, q)
it := s.client.Run(context.Background() /* TODO: pass ctx from request */, q)
count := 0
for {
var e DatastoreEntity
Expand Down Expand Up @@ -261,7 +261,7 @@ func (s *DatastoreStorage) ReadHistoryTx(datatype, realm, user, id string, conte
// TODO: handle pagination.
q := datastore.NewQuery(historyKind).Filter("service =", s.service).Filter("type =", datatype).Filter("realm =", realm).Filter("user_id =", user).Filter("id =", id).Order("rev").Limit(storage.MaxPageSize)
results := make([]DatastoreHistory, storage.MaxPageSize)
if _, err := s.client.GetAll(context.TODO, q, &results); err != nil {
if _, err := s.client.GetAll(context.Background() /* TODO: pass ctx from request */, q, &results); err != nil {
return err
}
for _, e := range results {
Expand Down Expand Up @@ -389,7 +389,7 @@ func (s *DatastoreStorage) Wipe(realm string) error {
}

func (s *DatastoreStorage) multiDelete(q *datastore.Query) (int, error) {
keys, err := s.client.GetAll(context.TODO, q.KeysOnly(), nil)
keys, err := s.client.GetAll(context.Background() /* TODO: pass ctx from request */, q.KeysOnly(), nil)
if err != nil {
return 0, err
}
Expand All @@ -400,7 +400,7 @@ func (s *DatastoreStorage) multiDelete(q *datastore.Query) (int, error) {
end = total
}
chunk := keys[i:end]
if err := s.client.DeleteMulti(context.TODO, chunk); err != nil {
if err := s.client.DeleteMulti(context.Background() /* TODO: pass ctx from request */, chunk); err != nil {
return total, err
}
}
Expand All @@ -411,9 +411,9 @@ func (s *DatastoreStorage) Tx(update bool) (storage.Tx, error) {
var err error
var dstx *datastore.Transaction
if update {
dstx, err = s.client.NewTransaction(context.TODO)
dstx, err = s.client.NewTransaction(context.Background() /* TODO: pass ctx from request */)
} else {
dstx, err = s.client.NewTransaction(context.TODO, datastore.ReadOnly)
dstx, err = s.client.NewTransaction(context.Background() /* TODO: pass ctx from request */, datastore.ReadOnly)
}
if err != nil {
return nil, err
Expand Down Expand Up @@ -469,13 +469,13 @@ func (s *DatastoreStorage) LockTx(lockName string, minFrequency time.Duration, t
func (s *DatastoreStorage) Init() error {
k := datastore.NameKey(metaKind, s.metaKey(metaVersion), nil)
meta := new(DatastoreMeta)
if err := s.client.Get(context.TODO, k, meta); err == datastore.ErrNoSuchEntity {
if err := s.client.Get(context.Background() /* TODO: pass ctx from request */, k, meta); err == datastore.ErrNoSuchEntity {
meta = &DatastoreMeta{
Key: k,
Name: metaVersion,
Value: storageVersion,
}
_, err := s.client.Put(context.TODO, k, meta)
_, err := s.client.Put(context.Background() /* TODO: pass ctx from request */, k, meta)
if err != nil {
return fmt.Errorf("cannot write datastore metadata: %v", err)
}
Expand Down

0 comments on commit bf618f5

Please sign in to comment.