Fixing IFTTT shared stories when sending two requests at the same time.

This commit is contained in:
Samuel Clay 2014-03-31 14:26:50 -07:00
parent 8e31eb0c70
commit b942c19673
2 changed files with 12 additions and 7 deletions

View file

@ -8,6 +8,7 @@ from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.conf import settings
from mongoengine.queryset import NotUniqueError
from mongoengine.queryset import OperationError
from apps.social.models import MSocialServices, MSocialSubscription, MSharedStory
from apps.social.tasks import SyncTwitterFriends, SyncFacebookFriends, SyncAppdotnetFriends
@ -659,12 +660,15 @@ def api_share_new_story(request):
"comments": comments,
"has_comments": bool(comments),
}
shared_story = MSharedStory.objects.create(**story_db)
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=user.pk)
for socialsub in socialsubs:
socialsub.needs_unread_recalc = True
socialsub.save()
logging.user(request, "~BM~FYSharing story from ~SB~FCIFTTT~FY: ~SB%s: %s" % (story_url, comments))
try:
shared_story = MSharedStory.objects.create(**story_db)
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=user.pk)
for socialsub in socialsubs:
socialsub.needs_unread_recalc = True
socialsub.save()
logging.user(request, "~BM~FYSharing story from ~SB~FCIFTTT~FY: ~SB%s: %s" % (story_url, comments))
except NotUniqueError:
logging.user(request, "~BM~FY~SBAlready~SN shared story from ~SB~FCIFTTT~FY: ~SB%s: %s" % (story_url, comments))
else:
logging.user(request, "~BM~FY~SBAlready~SN shared story from ~SB~FCIFTTT~FY: ~SB%s: %s" % (story_url, comments))

View file

@ -85,7 +85,8 @@
<img src="/media/img/logo_512.png" class="logo">
<h1>NewsBlur is in <span class="error404">maintenance mode</span></h1>
<div class="description">
<p>This will take about 5 minutes. This is one of those maintenance modes that you should be happy about, since I'm adding some new tables to the database. I can't say exactly what these tables are for (although if you care enough, <a href="http://github.com/samuelclay">check the source code on GitHub</a>). But if you're patient and can wait a few weeks, you'll be delighted by this mega-huge feature I've wanted to build for over two years now.</p>
<p>This will take about 5 minutes. This is the second half of two maintenance modes for the night. I run this maintenance about four times a year. Check the average load time graphs, they should go down to a nice even 0.1 sec on average after tonight's maintenance.</p>
<p>Technically what I'm doing is moving the primary mongo server to a secondary so I can shut it down and run a compaction. Takes a few hours. This is now done and I'm flipping back to the primary.</p>
<p>To pass the time, <a href="http://mlkshk.com/popular">check out what's popular on MLKSHK</a>.</p>
</div>
</div>