Closed wonderbeyond closed 6 years ago
As a workaround:
qs = self.filter_queryset()
rs = yield qs.find_all()
qs = self.filter_queryset()
count = yield qs.count()
Remember that getting a queryset does not execute anything, so no performance penalty involved.
Many thanks to @heynemann.
A shallow copy of a queryset also works:
qs = self.filter_queryset()
rs, count = yield [copy.copy(qs).find_all(), copy.copy(qs).count()]
However, I don't think it's a good idea to clean the internal filter state alter done find_all
or count
implicitly, which may cause confusion.
Do you think you can help with a Pull Request?
Here is my handler method:
I just want to get the result and the count at the same time. However, the
qs.count()
just get the total number of the records in db, not in myqs
.I've looked into motorengine source code, foud that
qs.find_all()
would clean the queryset's internal filter state after self use.len(rs)
is also not what I want, because I've done skip and limit on the queryset(infilter_queryset
method).Any helps? many thanks!