擅长:python、mysql、java
<p>使用<code>count</code>。如果你能分页,效率上的差别可以忽略不计。</p>
<pre><code>list_of_emails = EmailSent.query(EmailSent.unsub==True)
total_count = list_of_emails.count()
offset = int(args['offset'])
limit = int(args['limit'])
list_of_emails, next_cursor, more = list_of_emails.fetch_page(limit, offset=offset)
prev_offset = max(offset - limit, 0)
prev = True if offset else False
next_ = True if more else False
next_offset = ''
if next_:
next_offset = offset + limit
objects = map(lambda emails: func(emails), list_of_emails)
return {'objects': objects, 'total_count': total_count, 'prev': prev, 'next': next_, 'prev_offset': prev_offset,
'next_offset': next_offset}
</code></pre>