Fix Datastore "count" queries (#1201)

* Fix Datastore "count" queries

The objectify "count()" method doesn't work for result sets larger than 1000
elements, use the original trick from "count domains" that fetches the keys
and counts them.

* Added an SO link
This commit is contained in:
Michael Muller 2021-06-08 15:23:25 -04:00 committed by GitHub
parent a1b56b0521
commit 14ad56a392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -480,7 +480,13 @@ public class DatastoreTransactionManager implements TransactionManager {
@Override @Override
public long count() { public long count() {
return buildQuery().count(); // Objectify provides a count() function, but unfortunately that doesn't work if there are
// more than 1000 (the default response page size?) entries in the result set. We also use
// chunkAll() here as it provides a nice performance boost.
//
// There is some information on this issue on SO, see:
// https://stackoverflow.com/questions/751124/how-does-one-get-a-count-of-rows-in-a-datastore-model-in-google-app-engine
return Iterables.size(buildQuery().chunkAll().keys());
} }
@Override @Override