Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

something went horribly wrong with this merge

  • Loading branch information...
commit 947b163b4e959d4c629b34c9dcce2222d27317ad 1 parent 2253904
@smn smn authored
Showing with 23 additions and 4 deletions.
  1. +14 −2 vumi/persist/fields.py
  2. +9 −2 vumi/persist/model.py
View
16 vumi/persist/fields.py
@@ -529,10 +529,22 @@ def reverse_lookup(self, modelobj, manager=None):
mr = manager.riak_map_reduce()
bucket = manager.bucket_prefix + self.cls.bucket
mr.index(bucket, self.index_name, modelobj.key)
+ if manager.fetch_objects:
+ # Return the key and the data for this object.
+ # Allows us to populate the objects coming back from a
+ # map reduce in one single call. This is especially important
+ # for synchronous calls.
+ mr = mr.map(function="""function(v) {
+ return [[v.key, v.values[0]]]
+ }""")
return manager.run_map_reduce(mr, self.map_lookup_result)
- def map_lookup_result(self, manager, result):
- return self.cls.load(manager, result.get_key())
+ def map_lookup_result(self, manager, key_or_result_tuple):
+ try:
+ key, result = key_or_result_tuple
+ except ValueError:
+ key, result = key_or_result_tuple, None
+ return self.cls.load(manager, key, result)
def get_value(self, modelobj):
return ForeignKeyProxy(self, modelobj)
View
11 vumi/persist/model.py
@@ -130,13 +130,13 @@ def delete(self):
return self.manager.delete(self)
@classmethod
- def load(cls, manager, key):
+ def load(cls, manager, key, result=None):
"""Load an object from Riak.
:returns:
A deferred that fires with the new model object.
"""
- return manager.load(cls, key)
+ return manager.load(cls, key, result=result)
@classmethod
def by_index(cls, manager, return_keys=False, **kw):
@@ -192,6 +192,13 @@ def enable_search(cls, manager):
class Manager(object):
"""A wrapper around a Riak client."""
+ # By default we do not fetch the objects as part of a mapreduce call.
+ # This has the mapreduce return a list of keys which would require
+ # another set of calls to get the individual objects. For asynchronous
+ # managers this would be preferable, for synchronous managers one
+ # would likely want to fetch the objects as part of the mapreduce call.
+ fetch_objects = False
+
def __init__(self, client, bucket_prefix):
self.client = client
self.bucket_prefix = bucket_prefix
Please sign in to comment.
Something went wrong with that request. Please try again.