Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: impl/cloud/datastore.go

Issue 2492103003: Update cloud implementation w/ new datastore API (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/cloud/datastore.go
diff --git a/impl/cloud/datastore.go b/impl/cloud/datastore.go
index 969509d5d85f8f873b9ac5dc005c8f244becfa94..9542bf40c0db09eefcce8630942f3fe226f2b0b1 100644
--- a/impl/cloud/datastore.go
+++ b/impl/cloud/datastore.go
@@ -13,9 +13,9 @@ import (
"github.com/luci/luci-go/common/errors"
ds "github.com/luci/gae/service/datastore"
- "github.com/luci/gae/service/info"
"cloud.google.com/go/datastore"
+ "google.golang.org/api/iterator"
"golang.org/x/net/context"
)
@@ -26,10 +26,6 @@ type cloudDatastore struct {
func (cds *cloudDatastore) use(c context.Context) context.Context {
return ds.SetRawFactory(c, func(ic context.Context) ds.RawInterface {
- if ns := info.GetNamespace(ic); ns != "" {
- ic = datastore.WithNamespace(ic, ns)
- }
-
return &boundDatastore{
Context: ic,
cloudDatastore: cds,
@@ -111,7 +107,7 @@ func (bds *boundDatastore) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error {
}
nativeKey, err := it.Next(npls)
if err != nil {
- if err == datastore.Done {
+ if err == iterator.Done {
return nil
}
return normalizeError(err)
@@ -265,6 +261,9 @@ func (bds *boundDatastore) prepareNativeQuery(fq *ds.FinalizedQuery) *datastore.
if bds.transaction != nil {
nq = nq.Transaction(bds.transaction)
}
+ if ns := bds.kc.Namespace; ns != "" {
+ nq = nq.Namespace(ns)
+ }
// nativeFilter translates a filter field. If the translation fails, we'll
// pass the result through to the underlying datastore and allow it to
@@ -458,7 +457,13 @@ func (bds *boundDatastore) gaeKeysToNative(keys ...*ds.Key) []*datastore.Key {
var nativeKey *datastore.Key
for _, tok := range toks {
- nativeKey = datastore.NewKey(bds, tok.Kind, tok.StringID, tok.IntID, nativeKey)
+ nativeKey = &datastore.Key{
+ Kind: tok.Kind,
+ ID: tok.IntID,
+ Name: tok.StringID,
+ Parent: nativeKey,
+ Namespace: key.Namespace(),
+ }
}
nativeKeys[i] = nativeKey
}
@@ -474,8 +479,8 @@ func (bds *boundDatastore) nativeKeysToGAE(nativeKeys ...*datastore.Key) []*ds.K
toks = toks[:0]
cur := nativeKey
for {
- toks = append(toks, ds.KeyTok{Kind: cur.Kind(), IntID: cur.ID(), StringID: cur.Name()})
- cur = cur.Parent()
+ toks = append(toks, ds.KeyTok{Kind: cur.Kind, IntID: cur.ID, StringID: cur.Name})
+ cur = cur.Parent
if cur == nil {
break
}
@@ -486,7 +491,7 @@ func (bds *boundDatastore) nativeKeysToGAE(nativeKeys ...*datastore.Key) []*ds.K
ri := len(toks) - i - 1
toks[i], toks[ri] = toks[ri], toks[i]
}
- kc.Namespace = nativeKey.Namespace()
+ kc.Namespace = nativeKey.Namespace
keys[i] = kc.NewKeyToks(toks)
}
return keys
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698