From ac4e5e5382a7e785733d16748eb4ce797e60f1a3 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Wed, 20 Feb 2013 18:21:21 -0800 Subject: [PATCH] fetch_things2: Assert that a sort order is provided. Otherwise you end up in a bizarro infinite loop. --- r2/r2/lib/count.py | 3 ++- r2/r2/lib/utils/utils.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/r2/r2/lib/count.py b/r2/r2/lib/count.py index bafac4749..a783cc462 100644 --- a/r2/r2/lib/count.py +++ b/r2/r2/lib/count.py @@ -22,6 +22,7 @@ from r2.models import Link, Subreddit from r2.lib import utils +from r2.lib.db.operators import desc from pylons import g count_period = g.rising_period @@ -40,7 +41,7 @@ def get_link_counts(period = count_period): return dict((l._fullname, (0, l.sr_id)) for l in links) def get_sr_counts(): - srs = utils.fetch_things2(Subreddit._query()) + srs = utils.fetch_things2(Subreddit._query(sort=desc("_date"))) return dict((sr._fullname, sr._ups) for sr in srs) diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index 43caee4f3..cdb3d8c7f 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -770,6 +770,9 @@ def fetch_things2(query, chunk_size = 100, batch_fn = None, chunks = False): """Incrementally run query with a limit of chunk_size until there are no results left. batch_fn transforms the results for each chunk before returning.""" + + assert query._sort, "you must specify the sort order in your query!" + orig_rules = deepcopy(query._rules) query._limit = chunk_size items = list(query)