Permalink
Browse files

Moving shared story unread recalc to background task. Will greatly sp…

…eed up sharing.
  • Loading branch information...
1 parent db92d3c commit b2e52858eaa04dda7a13803aeff84e2897c2c453 @samuelclay committed Mar 19, 2013
Showing with 23 additions and 8 deletions.
  1. +1 −1 .gitignore
  2. +19 −2 apps/social/tasks.py
  3. +3 −5 apps/social/views.py
View
2 .gitignore
@@ -12,7 +12,7 @@ build/
.DS_Store
**/*.perspectivev*
data/
-config/certificates/*
+config/certificates
**/*.xcuserstate
UserInterfaceState.xcuserstate
UserInterfaceState\.xcuserstate
View
21 apps/social/tasks.py
@@ -1,5 +1,7 @@
+from bson.objectid import ObjectId
from celery.task import Task
-from apps.social.models import MSharedStory, MSocialProfile, MSocialServices
+from apps.social.models import MSharedStory, MSocialProfile, MSocialServices, MSocialSubscription
+from django.contrib.auth.models import User
from utils import log as logging
@@ -57,4 +59,19 @@ def run(self, **kwargs):
if not shared:
shared = MSharedStory.share_popular_stories(interactive=False, days=2)
-
+
+class UpdateRecalcForSubscription(Task):
+
+ def run(self, subscription_user_id, shared_story_id):
+ user = User.objects.get(pk=subscription_user_id)
+ socialsubs = MSocialSubscription.objects.filter(subscription_user_id=subscription_user_id)
+ logging.debug(" ---> ~FM~SNFlipping unread recalc for ~SB%s~SN subscriptions to ~SB%s's blurblog~SN" % (
+ socialsubs.count(),
+ user.username
+ ))
+ for socialsub in socialsubs:
+ socialsub.needs_unread_recalc = True
+ socialsub.save()
+
+ shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
+ shared_story.publish_update_to_subscribers()
View
8 apps/social/views.py
@@ -17,6 +17,7 @@
from apps.social.models import MSharedStory, MSocialServices, MSocialProfile, MSocialSubscription, MCommentReply
from apps.social.models import MInteraction, MActivity, MFollowRequest
from apps.social.tasks import PostToService, EmailCommentReplies, EmailStoryReshares
+from apps.social.tasks import UpdateRecalcForSubscription
from apps.analyzer.models import MClassifierTitle, MClassifierAuthor, MClassifierFeed, MClassifierTag
from apps.analyzer.models import apply_classifier_titles, apply_classifier_feeds, apply_classifier_authors, apply_classifier_tags
from apps.analyzer.models import get_classifiers_for_user, sort_classifiers_by_feed
@@ -519,10 +520,8 @@ def mark_story_as_shared(request):
shared_story = MSharedStory.objects.create(**story_db)
if source_user_id:
shared_story.set_source_user_id(int(source_user_id))
- socialsubs = MSocialSubscription.objects.filter(subscription_user_id=request.user.pk)
- for socialsub in socialsubs:
- socialsub.needs_unread_recalc = True
- socialsub.save()
+ UpdateRecalcForSubscription.delay(subscription_user_id=request.user.pk,
+ shared_story_id=str(shared_story.id))
logging.user(request, "~FCSharing ~FM%s: ~SB~FB%s" % (story.story_title[:20], comments[:30]))
else:
shared_story.comments = comments
@@ -533,7 +532,6 @@ def mark_story_as_shared(request):
if original_story_found:
story.count_comments()
- shared_story.publish_update_to_subscribers()
story = Feed.format_story(story)
check_all = not original_story_found

0 comments on commit b2e5285

Please sign in to comment.