Skip to content

Commit

Permalink
WCM-22: Combine query building, to aid debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
wosc committed Sep 6, 2024
1 parent cdd0af0 commit f52d10c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/src/zeit/contentquery/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ def connector(self):

@cachedproperty
def total_hits(self):
return self.connector.search_sql_count(self._build_query())
return self.connector.search_sql_count(self._build_query(order=False))

def __call__(self):
query = self._build_query()
query = query.order_by(sql(self.context.sql_order))
query = query.limit(self.rows).offset(self.start)
result = [ICMSContent(x) for x in self.connector.search_sql(query)]
return result

def _build_query(self):
def _build_query(self, order=True):
query = self.connector.query()
query = query.where(sql(self.context.sql_query))
query = self.add_clauses(query)
query = self.hide_dupes_clause(query)

if order: # not allowed by SQL when using `count()`
query = query.order_by(sql(self.context.sql_order))
query = query.limit(self.rows).offset(self.start)
return query

def add_clauses(self, query):
Expand Down

0 comments on commit f52d10c

Please sign in to comment.