diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index 1350132b5..a4cd22ea0 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -909,53 +909,6 @@ def common_subdomain(domain1, domain2): return "" -def link_from_url(path, filter_spam = False, multiple = True): - from pylons import c - from r2.models import IDBuilder, Link, Subreddit, NotFound - - if not path: - return - - try: - links = Link._by_url(path, c.site) - except NotFound: - return [] if multiple else None - - return filter_links(tup(links), filter_spam = filter_spam, - multiple = multiple) - -def filter_links(links, filter_spam = False, multiple = True): - # run the list through a builder to remove any that the user - # isn't allowed to see - from pylons import c - from r2.models import IDBuilder, Link, Subreddit, NotFound - links = IDBuilder([link._fullname for link in links], - skip = False).get_items()[0] - if not links: - return - - if filter_spam: - # first, try to remove any spam - links_nonspam = [ link for link in links - if not link._spam ] - if links_nonspam: - links = links_nonspam - - # if it occurs in one or more of their subscriptions, show them - # that one first - subs = set(Subreddit.user_subreddits(c.user, limit = None)) - def cmp_links(a, b): - if a.sr_id in subs and b.sr_id not in subs: - return -1 - elif a.sr_id not in subs and b.sr_id in subs: - return 1 - else: - return cmp(b._hot, a._hot) - links = sorted(links, cmp = cmp_links) - - # among those, show them the hottest one - return links if multiple else links[0] - def url_links_builder(url, exclude=None, num=None, after=None, reverse=None, count=None): from r2.lib.template_helpers import add_sr