mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-20 05:14:44 +00:00
Checking if stories are shared through redis before asking mongo.
This commit is contained in:
parent
af333e5382
commit
db2ffb0f87
2 changed files with 28 additions and 9 deletions
|
@ -581,10 +581,12 @@ def load_single_feed(request, feed_id):
|
|||
story_feed_id=feed.pk,
|
||||
story_hash__in=story_hashes)\
|
||||
.only('story_hash', 'starred_date', 'user_tags')
|
||||
shared_stories = MSharedStory.objects(user_id=user.pk,
|
||||
story_feed_id=feed_id,
|
||||
story_hash__in=story_hashes)\
|
||||
.only('story_hash', 'shared_date', 'comments')
|
||||
shared_story_hashes = MSharedStory.check_shared_story_hashes(user.pk, story_hashes)
|
||||
shared_stories = []
|
||||
if shared_story_hashes:
|
||||
shared_stories = MSharedStory.objects(user_id=user.pk,
|
||||
story_hash__in=shared_story_hashes)\
|
||||
.only('story_hash', 'shared_date', 'comments')
|
||||
starred_stories = dict([(story.story_hash, dict(starred_date=story.starred_date,
|
||||
user_tags=story.user_tags))
|
||||
for story in starred_stories])
|
||||
|
@ -781,9 +783,12 @@ def load_starred_stories(request):
|
|||
unsub_feed_ids = list(set(story_feed_ids).difference(set(usersub_ids)))
|
||||
unsub_feeds = Feed.objects.filter(pk__in=unsub_feed_ids)
|
||||
unsub_feeds = dict((feed.pk, feed.canonical(include_favicon=False)) for feed in unsub_feeds)
|
||||
shared_stories = MSharedStory.objects(user_id=user.pk,
|
||||
story_hash__in=story_hashes)\
|
||||
.only('story_hash', 'shared_date', 'comments')
|
||||
shared_story_hashes = MSharedStory.check_shared_story_hashes(user.pk, story_hashes)
|
||||
shared_stories = []
|
||||
if shared_story_hashes:
|
||||
shared_stories = MSharedStory.objects(user_id=user.pk,
|
||||
story_hash__in=shared_story_hashes)\
|
||||
.only('story_hash', 'shared_date', 'comments')
|
||||
shared_stories = dict([(story.story_hash, dict(shared_date=story.shared_date,
|
||||
comments=story.comments))
|
||||
for story in shared_stories])
|
||||
|
|
|
@ -1399,7 +1399,7 @@ class MSharedStory(mongo.Document):
|
|||
meta = {
|
||||
'collection': 'shared_stories',
|
||||
'indexes': [('user_id', '-shared_date'), ('user_id', 'story_feed_id'),
|
||||
'shared_date', 'story_guid', 'story_feed_id'],
|
||||
'shared_date', 'story_guid', 'story_feed_id', 'story_hash'],
|
||||
'index_drop_dups': True,
|
||||
'ordering': ['-shared_date'],
|
||||
'allow_inheritance': False,
|
||||
|
@ -1676,7 +1676,21 @@ class MSharedStory(mongo.Document):
|
|||
shared_story.publish_update_to_subscribers()
|
||||
|
||||
return shared
|
||||
|
||||
|
||||
@staticmethod
|
||||
def check_shared_story_hashes(user_id, story_hashes, r=None):
|
||||
if not r:
|
||||
r = redis.Redis(connection_pool=settings.REDIS_POOL)
|
||||
pipeline = r.pipeline()
|
||||
|
||||
for story_hash in story_hashes:
|
||||
feed_id, guid_hash = MStory.split_story_hash(story_hash)
|
||||
share_key = "S:%s:%s" % (feed_id, guid_hash)
|
||||
pipeline.sismember(share_key, user_id)
|
||||
shared_hashes = pipeline.execute()
|
||||
|
||||
return [story_hash for s, story_hash in enumerate(story_hashes) if shared_hashes[s]]
|
||||
|
||||
@classmethod
|
||||
def sync_all_redis(cls, drop=False):
|
||||
r = redis.Redis(connection_pool=settings.REDIS_POOL)
|
||||
|
|
Loading…
Add table
Reference in a new issue