يعترض / AppEngine: أفضل طريقة لحساب # من الكائنات التي تم إرجاعها بواسطة استعلام؟

StackOverflow https://stackoverflow.com/questions/5043001

  •  15-11-2019
  •  | 
  •  

سؤال

ماذا سيكون أفضل طريقة (أي كفاءة) لعد عدد الكائنات التي تم إرجاعها بواسطة استعلام، W / O فعلا تحميلها، باستخدام يعترض على APPENGINE ؟أنا أظن أن الأفضل هو جلب كل المفاتيح وعسق النتيجة: giveacodicetagpre.

لا يبدو أن لديك أي طريقة مخصصة للقيام بذلك.أي أفكار؟

هل كانت مفيدة؟

المحلول

Found it:

int n = Iterable<Key<MyEntity>> list = ofy().query(MyEntity.class)
      .filter("field", v).count();

It's that simple, though efficient because it retrieves all the keys. It's better to design your UI to handle unknown numbers of results (such as Google which gives clues to the number of pages but not the actual number)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top