Python formatting
This commit is contained in:
@ -104,7 +104,7 @@ class ActivityStream(RedisStore):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_objects_for_store(self, store):
|
def get_objects_for_store(self, store):
|
||||||
user = models.User.objects.get(id=store.split('-')[0])
|
user = models.User.objects.get(id=store.split("-")[0])
|
||||||
return self.get_statuses_for_user(user)
|
return self.get_statuses_for_user(user)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ r = redis.Redis(
|
|||||||
|
|
||||||
class RedisStore(ABC):
|
class RedisStore(ABC):
|
||||||
""" sets of ranked, related objects, like statuses for a user's feed """
|
""" sets of ranked, related objects, like statuses for a user's feed """
|
||||||
|
|
||||||
max_length = settings.MAX_STREAM_LENGTH
|
max_length = settings.MAX_STREAM_LENGTH
|
||||||
|
|
||||||
def get_value(self, obj):
|
def get_value(self, obj):
|
||||||
@ -26,9 +27,7 @@ class RedisStore(ABC):
|
|||||||
# 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
|
||||||
pipeline.zremrangebyrank(
|
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
||||||
store, 0, -1 * self.max_length
|
|
||||||
)
|
|
||||||
if not execute:
|
if not execute:
|
||||||
return pipeline
|
return pipeline
|
||||||
# and go!
|
# and go!
|
||||||
@ -47,9 +46,7 @@ class RedisStore(ABC):
|
|||||||
for obj in objs[: self.max_length]:
|
for obj in objs[: self.max_length]:
|
||||||
pipeline.zadd(store, self.get_value(obj))
|
pipeline.zadd(store, self.get_value(obj))
|
||||||
if objs:
|
if objs:
|
||||||
pipeline.zremrangebyrank(
|
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
||||||
store, 0, -1 * self.max_length
|
|
||||||
)
|
|
||||||
pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
def bulk_remove_objects_from_store(self, objs, store):
|
def bulk_remove_objects_from_store(self, objs, store):
|
||||||
@ -73,9 +70,7 @@ class RedisStore(ABC):
|
|||||||
|
|
||||||
# only trim the store if objects were added
|
# only trim the store if objects were added
|
||||||
if queryset.exists():
|
if queryset.exists():
|
||||||
pipeline.zremrangebyrank(
|
pipeline.zremrangebyrank(store, 0, -1 * self.max_length)
|
||||||
store, 0, -1 * self.max_length
|
|
||||||
)
|
|
||||||
pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
Reference in New Issue
Block a user