mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-30 09:18:20 -05:00
fetch_things2: Assert that a sort order is provided.
Otherwise you end up in a bizarro infinite loop.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user