From 3457860b957f078a446fe0ec477aecf17c5f8db3 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Tue, 31 Jul 2012 10:26:18 -0700 Subject: [PATCH] Don't count automatic subreddits against subscription limits. When getting a list of user subreddits, we'll check if they're subscribed to any automatic subreddits and remove them from the mix before doing the random selection. Then they'll be added back in. This is important to ensure that maintenance announcements aren't missed by users because the announcement wasn't in their subset of subscriptions. On reddit.com the automatic subreddits are /r/blog and /r/announcements. --- r2/r2/models/subreddit.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index f2a9de38f..bcd690bb5 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -506,9 +506,27 @@ class Subreddit(Thing, Printable): if user and user.has_subscribed: sr_ids = Subreddit.reverse_subscriber_ids(user) + # don't count automatic reddits against the limit + if g.automatic_reddits: + subscribed_automatic = [sr._id for sr in + Subreddit._by_name(g.automatic_reddits, + stale=stale).itervalues()] + + for sr_id in list(subscribed_automatic): + try: + sr_ids.remove(sr_id) + except ValueError: + subscribed_automatic.remove(sr_id) + else: + subscribed_automatic = [] + if limit and len(sr_ids) > limit: sr_ids.sort() sr_ids = cls.random_reddits(user.name, sr_ids, limit) + + # we can now add the automatic ones (that the user wants) back in + sr_ids += subscribed_automatic + return sr_ids if ids else Subreddit._byID(sr_ids, data=True, return_dict=False,