mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
Move vote-copying to CassandraVote.
This commit is contained in:
committed by
Neil Williams
parent
f429132c0f
commit
58dd0e5a8c
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user