mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Dirtying user subs and social subs on new mark read with story hash endpoint.
This commit is contained in:
parent
b71c4d7b35
commit
94df1aa6b0
2 changed files with 32 additions and 5 deletions
|
@ -661,23 +661,28 @@ class RUserStory:
|
|||
|
||||
p = r.pipeline()
|
||||
p2 = r2.pipeline()
|
||||
feed_ids = set()
|
||||
friend_ids = set()
|
||||
|
||||
if not isinstance(story_hashes, list):
|
||||
story_hashes = [story_hashes]
|
||||
|
||||
for story_hash in story_hashes:
|
||||
feed_id, _ = MStory.split_story_hash(story_hash)
|
||||
feed_ids.add(feed_id)
|
||||
|
||||
# Find other social feeds with this story to update their counts
|
||||
friend_key = "F:%s:F" % (user_id)
|
||||
share_key = "S:%s" % (story_hash)
|
||||
friends_with_shares = [int(f) for f in r.sinter(share_key, friend_key)]
|
||||
|
||||
friend_ids.update(friends_with_shares)
|
||||
cls.mark_read(user_id, feed_id, story_hash, social_user_ids=friends_with_shares, r=p, r2=p2)
|
||||
|
||||
p.execute()
|
||||
p2.execute()
|
||||
|
||||
|
||||
return feed_ids, friend_ids
|
||||
|
||||
@classmethod
|
||||
def mark_read(cls, user_id, story_feed_id, story_hash, social_user_ids=None, r=None, r2=None):
|
||||
if not r:
|
||||
|
|
|
@ -1023,11 +1023,33 @@ def mark_story_as_read(request):
|
|||
@ajax_login_required
|
||||
@json.json_view
|
||||
def mark_story_hashes_as_read(request):
|
||||
r = redis.Redis(connection_pool=settings.REDIS_PUBSUB_POOL)
|
||||
story_hashes = request.REQUEST.getlist('story_hash')
|
||||
|
||||
hashes_read = RUserStory.mark_story_hashes_read(request.user.pk, story_hashes)
|
||||
|
||||
return dict(code=1, hashes_read=hashes_read)
|
||||
feed_ids, friend_ids = RUserStory.mark_story_hashes_read(request.user.pk, story_hashes)
|
||||
|
||||
if friend_ids:
|
||||
socialsubs = MSocialSubscription.objects.filter(
|
||||
user_id=request.user.pk,
|
||||
subscription_user_id__in=friend_ids)
|
||||
for socialsub in socialsubs:
|
||||
if not socialsub.needs_unread_recalc:
|
||||
socialsub.needs_unread_recalc = True
|
||||
socialsub.save()
|
||||
r.publish(request.user.username, 'social:%s' % socialsub.subscription_user_id)
|
||||
|
||||
|
||||
# Also count on original subscription
|
||||
for feed_id in feed_ids:
|
||||
usersubs = UserSubscription.objects.filter(user=request.user.pk, feed=feed_id)
|
||||
if usersubs:
|
||||
usersub = usersubs[0]
|
||||
if not usersub.needs_unread_recalc:
|
||||
usersub.needs_unread_recalc = True
|
||||
usersub.save()
|
||||
r.publish(request.user.username, 'feed:%s' % feed_id)
|
||||
|
||||
return dict(code=1, story_hashes=story_hashes, feed_ids=feed_ids, friend_user_ids=friend_ids)
|
||||
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
|
|
Loading…
Add table
Reference in a new issue