diff --git a/r2/r2/lib/db/thing.py b/r2/r2/lib/db/thing.py index b5fd9a222..f4c7a2cd4 100644 --- a/r2/r2/lib/db/thing.py +++ b/r2/r2/lib/db/thing.py @@ -894,6 +894,7 @@ class Query(object): self._limit = kw.get('limit') self._data = kw.get('data') self._sort = kw.get('sort', ()) + self._filter_primary_sort_only = kw.get('filter_primary_sort_only', False) self._filter(*rules) @@ -934,8 +935,16 @@ class Query(object): def _dir(self, thing, reverse): ors = [] + + # this fun hack lets us simplify the query on /r/all + # for postgres-9 compatibility. please remove it when + # /r/all is precomputed. + sorts = range(len(self._sort)) + if self._filter_primary_sort_only: + sorts = [0] + #for each sort add and a comparison operator - for i in range(len(self._sort)): + for i in sorts: s = self._sort[i] if isinstance(s, operators.asc): diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 5c3819127..0b4af7819 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -774,7 +774,8 @@ class AllSR(FakeSubreddit): read_cache = True, write_cache = True, cache_time = 60, - data = True) + data = True, + filter_primary_sort_only=True) if time != 'all': q._filter(queries.db_times[time]) return q