fetch_things2: Assert that a sort order is provided.

Otherwise you end up in a bizarro infinite loop.
This commit is contained in:
Neil Williams
2013-02-20 18:21:21 -08:00
parent 89cea3e439
commit ac4e5e5382
2 changed files with 5 additions and 1 deletions

View File

@@ -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)

View File

@@ -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)