google app engine - Objectify/AppEngine: best way to count # of objects returned by a query? -


what best (i.e. efficient) way of counting number of objects returned query, w/o loading them, using objectify on appengine? i'm guessing best fetch keys , counting result:

public int getentitycount(long v) {     objectify ofy = objectifyservice.begin();     iterable<key<myentity>> list = ofy.query(myentity.class)             .filter("field", v).fetchkeys();     int n = 0;     (key<myentity> e : list)         n++;     return n; } 

doesn't seems have dedicated method doing that. ideas?

found it:

int n = iterable<key<myentity>> list = ofy().query(myentity.class)       .filter("field", v).count(); 

it's simple, though efficient because retrieves keys. it's better design ui handle unknown numbers of results (such google gives clues number of pages not actual number)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -