From 1936ed6b5fb58926e346caecad857d0114a581a0 Mon Sep 17 00:00:00 2001 From: Brian Simpson Date: Wed, 17 Jul 2013 00:17:59 -0400 Subject: [PATCH] DenormalizedRelation/View: replace opaque with kwargs. --- r2/r2/lib/db/tdb_cassandra.py | 10 +++++----- r2/r2/models/link.py | 14 +++++++------- r2/r2/models/vote.py | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/r2/r2/lib/db/tdb_cassandra.py b/r2/r2/lib/db/tdb_cassandra.py index 963531d41..b9dd9fe82 100644 --- a/r2/r2/lib/db/tdb_cassandra.py +++ b/r2/r2/lib/db/tdb_cassandra.py @@ -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 diff --git a/r2/r2/models/link.py b/r2/r2/models/link.py index 24c9c2ad4..b047c1ef3 100755 --- a/r2/r2/models/link.py +++ b/r2/r2/models/link.py @@ -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 diff --git a/r2/r2/models/vote.py b/r2/r2/models/vote.py index 79542c4a8..da764e588 100644 --- a/r2/r2/models/vote.py +++ b/r2/r2/models/vote.py @@ -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):