mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
DenormalizedRelation/View: replace opaque with kwargs.
This commit is contained in:
@@ -872,28 +872,28 @@ class DenormalizedRelation(object):
|
||||
default_validation_class=UTF8_TYPE)
|
||||
|
||||
@classmethod
|
||||
def value_for(cls, thing1, thing2, opaque):
|
||||
def value_for(cls, thing1, thing2, **kw):
|
||||
"""Return a value to store for a relationship between thing1/thing2."""
|
||||
raise NotImplementedError()
|
||||
|
||||
@classmethod
|
||||
def create(cls, thing1, thing2s, opaque=None):
|
||||
def create(cls, thing1, thing2s, **kw):
|
||||
"""Create a relationship between thing1 and thing2s.
|
||||
|
||||
If there are any other views of this data, they will be updated as
|
||||
well.
|
||||
|
||||
Takes an optional parameter "opaque" which can be used by views
|
||||
Takes kwargs which can be used by views
|
||||
or value_for to get additional information.
|
||||
|
||||
"""
|
||||
thing2s = tup(thing2s)
|
||||
values = {thing2._id36 : cls.value_for(thing1, thing2, opaque)
|
||||
values = {thing2._id36 : cls.value_for(thing1, thing2, **kw)
|
||||
for thing2 in thing2s}
|
||||
cls._cf.insert(thing1._id36, values)
|
||||
|
||||
for view in cls._views:
|
||||
view.create(thing1, thing2s, opaque)
|
||||
view.create(thing1, thing2s, **kw)
|
||||
|
||||
if cls._write_last_modified:
|
||||
from r2.models.last_modified import LastModified
|
||||
|
||||
@@ -1471,7 +1471,7 @@ class GildedCommentsByAccount(tdb_cassandra.DenormalizedRelation):
|
||||
_views = []
|
||||
|
||||
@classmethod
|
||||
def value_for(cls, thing1, thing2, opaque):
|
||||
def value_for(cls, thing1, thing2):
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
@@ -1493,7 +1493,7 @@ class GildingsByThing(tdb_cassandra.View):
|
||||
return [int(account_id, 36) for account_id in columns.iterkeys()]
|
||||
|
||||
@classmethod
|
||||
def create(cls, user, things, opaque):
|
||||
def create(cls, user, things):
|
||||
for thing in things:
|
||||
cls._set_values(thing._fullname, {user._id36: ""})
|
||||
|
||||
@@ -1533,7 +1533,7 @@ class GildingsByDay(tdb_cassandra.View):
|
||||
return gildings
|
||||
|
||||
@classmethod
|
||||
def create(cls, user, things, opaque):
|
||||
def create(cls, user, things):
|
||||
key = cls._rowkey(datetime.now(g.tz))
|
||||
|
||||
columns = {}
|
||||
@@ -1552,7 +1552,7 @@ class GildingsByDay(tdb_cassandra.View):
|
||||
|
||||
class _SaveHideByAccount(tdb_cassandra.DenormalizedRelation):
|
||||
@classmethod
|
||||
def value_for(cls, thing1, thing2, opaque):
|
||||
def value_for(cls, thing1, thing2):
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
@@ -1660,7 +1660,7 @@ class _ThingSavesBySubreddit(tdb_cassandra.View):
|
||||
return sorted([sr.name for sr in srs])
|
||||
|
||||
@classmethod
|
||||
def create(cls, user, things, opaque):
|
||||
def create(cls, user, things):
|
||||
for thing in things:
|
||||
rowkey = cls._rowkey(user, thing)
|
||||
column = cls._column(user, thing)
|
||||
@@ -1790,7 +1790,7 @@ class CommentsByAccount(tdb_cassandra.DenormalizedRelation):
|
||||
_views = []
|
||||
|
||||
@classmethod
|
||||
def value_for(cls, thing1, thing2, opaque):
|
||||
def value_for(cls, thing1, thing2):
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
@@ -1804,7 +1804,7 @@ class LinksByAccount(tdb_cassandra.DenormalizedRelation):
|
||||
_views = []
|
||||
|
||||
@classmethod
|
||||
def value_for(cls, thing1, thing2, opaque):
|
||||
def value_for(cls, thing1, thing2):
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -67,11 +67,11 @@ class VotesByAccount(tdb_cassandra.DenormalizedRelation):
|
||||
@classmethod
|
||||
def copy_from(cls, pgvote):
|
||||
rel = cls.rel(Account, pgvote._thing2.__class__)
|
||||
rel.create(pgvote._thing1, pgvote._thing2, opaque=pgvote)
|
||||
rel.create(pgvote._thing1, pgvote._thing2, pgvote=pgvote)
|
||||
|
||||
@classmethod
|
||||
def value_for(cls, thing1, thing2, opaque):
|
||||
return opaque._name
|
||||
def value_for(cls, thing1, thing2, pgvote):
|
||||
return pgvote._name
|
||||
|
||||
|
||||
class LinkVotesByAccount(VotesByAccount):
|
||||
|
||||
Reference in New Issue
Block a user