precompute toplinks

This commit is contained in:
spez
2008-09-30 10:59:23 -07:00
parent 43ef060417
commit 9bfdd5e5ee
3 changed files with 13 additions and 5 deletions

View File

@@ -260,10 +260,7 @@ class ToplinksController(ListingController):
title_text = _('top scoring links')
def query(self):
q = Link._query(Link.c.top_link == True,
sort = desc('_hot'),
*c.site.query_rules())
return q
return c.site.get_links('toplinks', 'all')
@validate(VSrMask('srs'))
def GET_listing(self, **env):

View File

@@ -18,7 +18,8 @@ db_sorts = dict(hot = (desc, '_hot'),
new = (desc, '_date'),
top = (desc, '_score'),
controversial = (desc, '_controversy'),
old = (asc, '_date'))
old = (asc, '_date'),
toplinks = (desc, '_hot'))
def db_sort(sort):
cls, col = db_sorts[sort]
@@ -179,6 +180,10 @@ def get_links(sr, sort, time):
"""General link query for a subreddit."""
q = Link._query(Link.c.sr_id == sr._id,
sort = db_sort(sort))
if sort == 'toplinks':
q._filter(Link.c.top_link == True)
if time != 'all':
q._filter(db_times[time])
return make_results(q)
@@ -298,6 +303,7 @@ def new_link(link):
results = all_queries(get_links, sr, ('hot', 'new', 'old'), ['all'])
results.extend(all_queries(get_links, sr, ('top', 'controversial'), db_times.keys()))
results.append(get_submitted(author, 'new', 'all'))
results.append(get_links(sr, 'toplinks', 'all'))
if link._deleted:
add_queries(results, delete_item = link)
@@ -328,6 +334,7 @@ def new_vote(vote):
sr = item.subreddit_slow
results = all_queries(get_links, sr, ('hot', 'new'), ['all'])
results.extend(all_queries(get_links, sr, ('top', 'controversial'), db_times.keys()))
results.append(get_links(sr, 'toplinks', 'all'))
add_queries(results)
#must update both because we don't know if it's a changed vote
@@ -366,6 +373,8 @@ def add_all_srs():
for sr in fetch_things2(q):
add_queries(all_queries(get_links, sr, ('hot', 'new', 'old'), ['all']))
add_queries(all_queries(get_links, sr, ('top', 'controversial'), db_times.keys()))
add_queries([get_links(sr, 'toplinks', 'all')])
def update_user(user):
if isinstance(user, str):

View File

@@ -509,6 +509,8 @@ class DefaultSR(FakeSubreddit):
else:
q = Link._query(Link.c.sr_id == sr_ids,
sort = queries.db_sort(sort))
if sort == 'toplinks':
q._filter(Link.c.top_link == True)
if time != 'all':
q._filter(queries.db_times[time])
return q