Example #1
0
    def get_links_sr_ids(self, sr_ids, sort, time, link_cls = None):
        from r2.lib.db import queries
        from r2.models import Link

        if not link_cls:
            link_cls = Link

        if not sr_ids:
            srs = []
        else:
            srs = Subreddit._byID(sr_ids, return_dict = False)

        if g.use_query_cache:
            results = []
            for sr in srs:
                results.append(queries.get_links(sr, sort, time))
            return queries.merge_cached_results(*results)
        else:
            q = link_cls._query(link_cls.c.sr_id == sr_ids,
                            sort = queries.db_sort(sort))
            if sort == 'toplinks':
                q._filter(link_cls.c.top_link == True)
            elif sort == 'blessed':
                q._filter(link_cls.c.blessed == True)
            if time != 'all':
                q._filter(queries.db_times[time])
            return q
Example #2
0
    def get_links_sr_ids(self, sr_ids, sort, time, link_cls=None):
        from r2.lib.db import queries
        from r2.models import Link

        if not link_cls:
            link_cls = Link

        if not sr_ids:
            srs = []
        else:
            srs = Subreddit._byID(sr_ids, return_dict=False)

        if g.use_query_cache:
            results = []
            for sr in srs:
                results.append(queries.get_links(sr, sort, time))
            return queries.merge_cached_results(*results)
        else:
            q = link_cls._query(link_cls.c.sr_id == sr_ids,
                                sort=queries.db_sort(sort))
            if sort == 'toplinks':
                q._filter(link_cls.c.top_link == True)
            elif sort == 'blessed':
                q._filter(link_cls.c.blessed == True)
            if time != 'all':
                q._filter(queries.db_times[time])
            return q
Example #3
0
    def get_links_sr_ids(self, sr_ids, sort, time):
        from r2.lib.db import queries
        from r2.models import Link

        if not sr_ids:
            return []
        else:
            srs = Subreddit._byID(sr_ids, return_dict=False)

        if g.use_query_cache:
            results = []
            for sr in srs:
                results.append(queries.get_links(sr, sort, time))
            return queries.merge_cached_results(*results)
        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