mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51:08 +00:00
Add add_object_to_stores function
This should enable some useful refactoring to allow us to cache some results of expensive queries better.
This commit is contained in:
parent
e909cbfd4a
commit
9c54030b61
1 changed files with 7 additions and 3 deletions
|
@ -16,12 +16,12 @@ class RedisStore(ABC):
|
||||||
"""the object and rank"""
|
"""the object and rank"""
|
||||||
return {obj.id: self.get_rank(obj)}
|
return {obj.id: self.get_rank(obj)}
|
||||||
|
|
||||||
def add_object_to_related_stores(self, obj, execute=True):
|
def add_object_to_stores(self, obj, stores, execute=True):
|
||||||
"""add an object to all suitable stores"""
|
"""add an object to a given set of stores"""
|
||||||
value = self.get_value(obj)
|
value = self.get_value(obj)
|
||||||
# we want to do this as a bulk operation, hence "pipeline"
|
# we want to do this as a bulk operation, hence "pipeline"
|
||||||
pipeline = r.pipeline()
|
pipeline = r.pipeline()
|
||||||
for store in self.get_stores_for_object(obj):
|
for store in stores:
|
||||||
# add the status to the feed
|
# add the status to the feed
|
||||||
pipeline.zadd(store, value)
|
pipeline.zadd(store, value)
|
||||||
# trim the store
|
# trim the store
|
||||||
|
@ -32,6 +32,10 @@ class RedisStore(ABC):
|
||||||
# and go!
|
# and go!
|
||||||
return pipeline.execute()
|
return pipeline.execute()
|
||||||
|
|
||||||
|
def add_object_to_related_stores(self, obj, execute=True):
|
||||||
|
"""add an object to all suitable stores"""
|
||||||
|
return self.add_object_to_stores(obj, self.get_stores_for_object(obj), execute)
|
||||||
|
|
||||||
def remove_object_from_related_stores(self, obj, stores=None):
|
def remove_object_from_related_stores(self, obj, stores=None):
|
||||||
"""remove an object from all stores"""
|
"""remove an object from all stores"""
|
||||||
# if the stoers are provided, the object can just be an id
|
# if the stoers are provided, the object can just be an id
|
||||||
|
|
Loading…
Reference in a new issue