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

Unified Diff: impl/memory/datastore_query_execution.go

Issue 1367003002: Add missing Count api (Closed) Base URL: https://github.com/luci/gae.git@move_serialization_helpers
Patch Set: Created 5 years, 3 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: impl/memory/datastore_query_execution.go
diff --git a/impl/memory/datastore_query_execution.go b/impl/memory/datastore_query_execution.go
index 758f7933f6749f21b94d43cbcff0b05659650edd..4dd99d25a250339bde093c129ad2eee61a982c79 100644
--- a/impl/memory/datastore_query_execution.go
+++ b/impl/memory/datastore_query_execution.go
@@ -163,6 +163,20 @@ func parseSuffix(ns string, suffixFormat []ds.IndexColumn, suffix []byte, count
return
}
+func countQuery(fq *ds.FinalizedQuery, ns string, isTxn bool, idx, head *memStore) (ret int64, err error) {
+ if len(fq.Project()) == 0 && !fq.KeysOnly() {
+ fq, err = fq.Original().KeysOnly(true).Finalize()
+ if err != nil {
+ return
+ }
+ }
+ err = executeQuery(fq, ns, isTxn, idx, head, func(_ *ds.Key, _ ds.PropertyMap, _ ds.CursorCB) bool {
+ ret++
+ return true
+ })
+ return
+}
+
func executeQuery(fq *ds.FinalizedQuery, ns string, isTxn bool, idx, head *memStore, cb ds.RawRunCB) error {
rq, err := reduce(fq, ns, isTxn)
if err == ds.ErrNullQuery {

Powered by Google App Engine
This is Rietveld 408576698