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.
This commit is contained in:
Neil Williams
2012-07-31 10:26:18 -07:00
parent ab13e13170
commit 3457860b95

View File

@@ -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,