def get_links(cls, event_id): link_ids = cls._get_related_link_ids(event_id) links = Link._byID(link_ids, data=True, return_dict=False) links.sort(key=lambda L: L.num_comments, reverse=True) sr_ids = set(L.sr_id for L in links) subreddits = Subreddit._byID(sr_ids, data=True) wrapped = [] for link in links: w = Wrapped(link) if w._spam or w._deleted: continue if not getattr(w, "allow_liveupdate", True): continue w.subreddit = subreddits[link.sr_id] # ideally we'd check if the user can see the subreddit, but by # doing this we keep everything user unspecific which makes caching # easier. if w.subreddit.type == "private": continue comment_label = ungettext("comment", "comments", link.num_comments) w.comments_label = strings.number_label % dict( num=link.num_comments, thing=comment_label) wrapped.append(w) return wrapped