Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Continue to write "subscriber" SRMember relation objects.
Browse files Browse the repository at this point in the history
These are being used by the data team and will need to be written
until they are able to read the new `SubscribedSubredditsByAccount`
from Cassandra.
  • Loading branch information
bsimpson63 committed Jun 30, 2015
1 parent 6733326 commit 7c5f464
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions r2/r2/models/subreddit.py
Expand Up @@ -57,6 +57,7 @@
from r2.lib.strings import strings, Score
from r2.lib.filters import _force_unicode
from r2.lib.db import tdb_cassandra
from r2.lib.db.tdb_sql import CreationError
from r2.models.wiki import WikiPage, ImagesByWikiPage
from r2.models.trylater import TryLater, TryLaterBySubject
from r2.lib.merge import ConflictException
Expand Down Expand Up @@ -1135,17 +1136,20 @@ def is_subscriber(self, user):
def add_subscriber(self, user):
SubscribedSubredditsByAccount.create(user, self)
SubscriptionsByDay.create(self, user)
add_legacy_subscriber(self, user)
self._incr('_ups', 1)

@classmethod
def subscribe_multiple(cls, user, srs):
SubscribedSubredditsByAccount.create(user, srs)
SubscriptionsByDay.create(srs, user)
for sr in srs:
add_legacy_subscriber(sr, user)
sr._incr('_ups', 1)

def remove_subscriber(self, user):
SubscribedSubredditsByAccount.destroy(user, self)
remove_legacy_subscriber(self, user)
self._incr('_ups', -1)

@classmethod
Expand Down Expand Up @@ -2436,6 +2440,21 @@ def is_superuser(self):
)


def add_legacy_subscriber(sr, user):
rel = SRMember(sr, user, "subscriber")
try:
rel._commit()
except CreationError:
pass


def remove_legacy_subscriber(sr, user):
rels = SRMember._fast_query([sr], [user], "subscriber")
rel = rels.get((sr, user, "subscriber"))
if rel:
rel._delete()


class SubredditTempBan(object):
def __init__(self, sr, kind, victim, banner, duration):
self.sr = sr._id36
Expand Down

0 comments on commit 7c5f464

Please sign in to comment.