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

Unified Diff: service/datastore/key.go

Issue 2007123002: datastore: Update AllocateIDs to take keys. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Created 4 years, 7 months 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
Index: service/datastore/key.go
diff --git a/service/datastore/key.go b/service/datastore/key.go
index 2071bfb7b2ad01ceed9c42592d5d6ba01fb6b053..85dd1c4508b95d05ae9d44f4a8a70feb6a927eb6 100644
--- a/service/datastore/key.go
+++ b/service/datastore/key.go
@@ -414,14 +414,27 @@ func (k *Key) GQL() string {
}
// Equal returns true iff the two keys represent identical key values.
-func (k *Key) Equal(other *Key) (ret bool) {
+func (k *Key) Equal(other *Key) bool {
+ return k.SameKind(other) && (k.LastTok() == other.LastTok())
+}
+
+// SameKind asserts that other refers to the same entity as k. This checks the
+// full lineage of the key.
+func (k *Key) SameKind(other *Key) (ret bool) {
ret = (k.appID == other.appID &&
k.namespace == other.namespace &&
len(k.toks) == len(other.toks))
if ret {
for i, t := range k.toks {
- if ret = t == other.toks[i]; !ret {
- return
+ if i == len(k.toks)-1 {
+ // Last token: check only Kind.
+ if ret = (t.Kind == other.toks[i].Kind); !ret {
+ return
+ }
+ } else {
+ if ret = t == other.toks[i]; !ret {
+ return
+ }
}
}
}

Powered by Google App Engine
This is Rietveld 408576698