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)