diff --git a/r2/r2/models/vote.py b/r2/r2/models/vote.py index 2bd612183..2fc150591 100644 --- a/r2/r2/models/vote.py +++ b/r2/r2/models/vote.py @@ -63,6 +63,23 @@ class CassandraVote(tdb_cassandra.Relation): raise TdbException("Can't find relation for %r(%r,%r)" % (cls, thing1_cls, thing2_cls)) + @classmethod + def _copy_from(cls, v): + voter = v._thing1 + votee = v._thing2 + cvc = cls._rel(Account, votee.__class__) + try: + cv = cvc._fast_query(voter._id36, votee._id36) + except tdb_cassandra.NotFound: + cv = cvc(thing1_id = voter._id36, thing2_id = votee._id36) + cv.name = v._name + cv.valid_user, cv.valid_thing = v.valid_user, v.valid_thing + if hasattr(v, 'ip'): + cv.ip = v.ip + if getattr(v, 'organic', False) or hasattr(cv, 'organic'): + cv.organic = getattr(v, 'organic', False) + cv._commit() + class VotesByLink(tdb_cassandra.View): _use_db = True @@ -218,22 +235,9 @@ class Vote(MultiRelation('vote', # now write it out to Cassandra. We'll write it out to both # this way for a while - voter = v._thing1 - votee = v._thing2 - cvc = CassandraVote._rel(Account, votee.__class__) - try: - cv = cvc._fast_query(voter._id36, votee._id36) - except tdb_cassandra.NotFound: - cv = cvc(thing1_id = voter._id36, thing2_id = votee._id36) - cv.name = v._name - cv.valid_user, cv.valid_thing = v.valid_user, v.valid_thing - if hasattr(v, 'ip'): - cv.ip = v.ip - if getattr(v, 'organic', False) or hasattr(cv, 'organic'): - cv.organic = getattr(v, 'organic', False) - cv._commit() + CassandraVote._copy_from(v) - queries.changed(votee, True) + queries.changed(v._thing2, True) return v