mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-05 03:00:15 -04:00
Make special_reddits use SRMember lookup rather than special query.
This commit is contained in:
committed by
Neil Williams
parent
27f99dc881
commit
04e3226128
@@ -484,7 +484,6 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
"""
|
||||
if container and container.is_moderator(c.user):
|
||||
container.remove_moderator(c.user)
|
||||
Subreddit.special_reddits(c.user, "moderator", _update=True)
|
||||
ModAction.create(container, c.user, 'removemoderator', target=c.user,
|
||||
details='remove_self')
|
||||
|
||||
@@ -498,7 +497,6 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
"""
|
||||
if container and container.is_contributor(c.user):
|
||||
container.remove_contributor(c.user)
|
||||
Subreddit.special_reddits(c.user, "contributor", _update=True)
|
||||
|
||||
|
||||
_sr_friend_types = (
|
||||
@@ -561,9 +559,6 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
if type == "friend" and c.user.gold:
|
||||
c.user.friend_rels_cache(_update=True)
|
||||
|
||||
if type in ("moderator", "contributor"):
|
||||
Subreddit.special_reddits(victim, type, _update=True)
|
||||
|
||||
@validatedForm(VUser(),
|
||||
VModhash(),
|
||||
ip = ValidIP(),
|
||||
@@ -644,9 +639,6 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
c.user.friend_rels_cache(_update=True)
|
||||
c.user.add_friend_note(friend, note or '')
|
||||
|
||||
if type in ("moderator", "contributor"):
|
||||
Subreddit.special_reddits(friend, type, _update=True)
|
||||
|
||||
cls = dict(friend=FriendList,
|
||||
moderator=ModList,
|
||||
moderator_invite=ModList,
|
||||
@@ -681,7 +673,6 @@ class ApiController(RedditController, OAuth2ResourceController):
|
||||
|
||||
ModAction.create(c.site, c.user, "acceptmoderatorinvite")
|
||||
c.site.add_moderator(c.user)
|
||||
Subreddit.special_reddits(c.user, "moderator", _update=True)
|
||||
notify_user_added("accept_moderator_invite", c.user, c.user, c.site)
|
||||
jquery.refresh()
|
||||
|
||||
|
||||
@@ -96,4 +96,3 @@ def subs_contribs(sr_name = 'betateam'):
|
||||
for rel in rels:
|
||||
if rel._name == 'subscriber':
|
||||
sr.add_contributor(rel._thing2)
|
||||
Subreddit.special_reddits(rel._thing2, 'contributor', _update=True)
|
||||
|
||||
@@ -672,25 +672,13 @@ class Subreddit(Thing, Printable):
|
||||
limit=g.num_default_reddits,
|
||||
stale=stale)
|
||||
|
||||
@classmethod
|
||||
@memoize('subreddit.special_reddits')
|
||||
def special_reddits_cache(cls, user_id, query_param):
|
||||
reddits = SRMember._query(SRMember.c._name == query_param,
|
||||
SRMember.c._thing2_id == user_id,
|
||||
#hack to prevent the query from
|
||||
#adding it's own date
|
||||
sort = (desc('_t1_ups'), desc('_t1_date')),
|
||||
eager_load = True,
|
||||
thing_data = True,
|
||||
limit = 100)
|
||||
|
||||
return [ sr._thing1_id for sr in reddits ]
|
||||
|
||||
# Used to pull all of the SRs a given user moderates or is a contributor
|
||||
# to (which one is controlled by query_param)
|
||||
@classmethod
|
||||
def special_reddits(cls, user, query_param, _update=False):
|
||||
return cls.special_reddits_cache(user._id, query_param, _update=_update)
|
||||
def special_reddits(cls, user, query_param):
|
||||
lookup = getattr(cls, 'reverse_%s_ids' % query_param)
|
||||
return lookup(user)
|
||||
|
||||
def is_subscriber_defaults(self, user):
|
||||
if user.has_subscribed:
|
||||
|
||||
Reference in New Issue
Block a user