def get_links_sr_ids(self, sr_ids, sort, time): from r2.lib.db import queries from r2.models import Link from r2.lib.normalized_hot import expand_children if not sr_ids: return [] else: srs = Subsciteit._byID(sr_ids, data=True, return_dict = False) if g.use_query_cache: srs = expand_children(srs) results = [queries.get_links(sr, sort, time,no_children=True) for sr in srs] return queries.merge_results(*results) else: sr_ids = expand_children(sr_ids,byID=True) q = Link._query(Link.c.sr_id == sr_ids, sort = queries.db_sort(sort), data=True) if time != 'all': q._filter(queries.db_times[time]) return q
def _get_links(sr_id, sort, time,no_children=False): """General link query for a subsciteit.""" #Get the children if there are any... from r2.lib.normalized_hot import expand_children #Are we building a lot of them? if not no_children: srs = expand_children(sr_id,byID=True) results = [_get_links(sr_id,sort,time,no_children=True) for sr_id in srs] return merge_results(*results) q = Link._query(Link.c.sr_id == sr_id, sort = db_sort(sort), data = True) if time != 'all': q._filter(db_times[time]) res = make_results(q) return res