From f52d10c5a6fdad3fe47fa93c7cb7f8f1ee3f9cd8 Mon Sep 17 00:00:00 2001 From: Wolfgang Schnerring Date: Fri, 6 Sep 2024 11:44:22 +0200 Subject: [PATCH] WCM-22: Combine query building, to aid debugging --- core/src/zeit/contentquery/query.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/zeit/contentquery/query.py b/core/src/zeit/contentquery/query.py index 61ba1a6d3e..588e9dab9e 100644 --- a/core/src/zeit/contentquery/query.py +++ b/core/src/zeit/contentquery/query.py @@ -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):