Skip to content

Commit

Permalink
fix: count perfs when using order by (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpofredc authored May 17, 2022
1 parent ae48701 commit ac54741
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/utils_flask_sqla/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,18 @@ def query(self):
nb_result_without_filter = q.count()

if self.filters:
q = self.build_query_filters(q, self.filters)
q = self.build_query_order(q, self.filters)
unordered_q = self.build_query_filters(q, self.filters)
q = self.build_query_order(unordered_q, self.filters)
nb_results = unordered_q.count()
else:
nb_results = q.count()

# Si la limite spécifiée est égale à -1
# les paramètres limit et offset ne sont pas pris en compte
if self.limit == -1:
data = q.all()
else:
data = q.limit(self.limit).offset(self.offset * self.limit).all()
nb_results = q.count()

return data, nb_result_without_filter, nb_results

Expand Down

0 comments on commit ac54741

Please sign in to comment.