mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-05 16:49:45 +00:00
Fixing redis/mongo logging accidentally duping logs on fast requests.
This commit is contained in:
parent
888778b670
commit
b8efcd0713
4 changed files with 37 additions and 32 deletions
|
@ -346,7 +346,7 @@ class UserSubscription(models.Model):
|
||||||
return code, message, us
|
return code, message, us
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def feeds_with_updated_counts(cls, user, feed_ids=None, check_fetch_status=False):
|
def feeds_with_updated_counts(cls, user, feed_ids=None, check_fetch_status=False, force=False):
|
||||||
feeds = {}
|
feeds = {}
|
||||||
|
|
||||||
# Get subscriptions for user
|
# Get subscriptions for user
|
||||||
|
@ -355,15 +355,15 @@ class UserSubscription(models.Model):
|
||||||
if feed_ids:
|
if feed_ids:
|
||||||
user_subs = user_subs.filter(feed__in=feed_ids)
|
user_subs = user_subs.filter(feed__in=feed_ids)
|
||||||
|
|
||||||
|
|
||||||
UNREAD_CUTOFF = datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD)
|
UNREAD_CUTOFF = datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD)
|
||||||
|
|
||||||
for i, sub in enumerate(user_subs):
|
for i, sub in enumerate(user_subs):
|
||||||
# Count unreads if subscription is stale.
|
# Count unreads if subscription is stale.
|
||||||
if (sub.needs_unread_recalc or
|
if (force or
|
||||||
|
sub.needs_unread_recalc or
|
||||||
sub.unread_count_updated < UNREAD_CUTOFF or
|
sub.unread_count_updated < UNREAD_CUTOFF or
|
||||||
sub.oldest_unread_story_date < UNREAD_CUTOFF):
|
sub.oldest_unread_story_date < UNREAD_CUTOFF):
|
||||||
sub = sub.calculate_feed_scores(silent=True)
|
sub = sub.calculate_feed_scores(silent=True, force=force)
|
||||||
if not sub: continue # TODO: Figure out the correct sub and give it a new feed_id
|
if not sub: continue # TODO: Figure out the correct sub and give it a new feed_id
|
||||||
|
|
||||||
feed_id = sub.feed_id
|
feed_id = sub.feed_id
|
||||||
|
|
|
@ -424,7 +424,7 @@ def refresh_feeds(request):
|
||||||
feeds[feed_id]['favicon_color'] = feed_icons[feed_id].color
|
feeds[feed_id]['favicon_color'] = feed_icons[feed_id].color
|
||||||
feeds[feed_id]['favicon_fetching'] = feed.get('favicon_fetching')
|
feeds[feed_id]['favicon_fetching'] = feed.get('favicon_fetching')
|
||||||
|
|
||||||
user_subs = UserSubscription.objects.select_related('feed').filter(user=user, active=True)
|
user_subs = UserSubscription.objects.filter(user=user, active=True)
|
||||||
sub_feed_ids = [s.feed_id for s in user_subs]
|
sub_feed_ids = [s.feed_id for s in user_subs]
|
||||||
|
|
||||||
if favicons_fetching:
|
if favicons_fetching:
|
||||||
|
@ -471,12 +471,13 @@ def interactions_count(request):
|
||||||
def feed_unread_count(request):
|
def feed_unread_count(request):
|
||||||
user = request.user
|
user = request.user
|
||||||
feed_ids = request.REQUEST.getlist('feed_id')
|
feed_ids = request.REQUEST.getlist('feed_id')
|
||||||
|
force = request.REQUEST.get('force', False)
|
||||||
social_feed_ids = [feed_id for feed_id in feed_ids if 'social:' in feed_id]
|
social_feed_ids = [feed_id for feed_id in feed_ids if 'social:' in feed_id]
|
||||||
feed_ids = list(set(feed_ids) - set(social_feed_ids))
|
feed_ids = list(set(feed_ids) - set(social_feed_ids))
|
||||||
|
|
||||||
feeds = {}
|
feeds = {}
|
||||||
if feed_ids:
|
if feed_ids:
|
||||||
feeds = UserSubscription.feeds_with_updated_counts(user, feed_ids=feed_ids)
|
feeds = UserSubscription.feeds_with_updated_counts(user, feed_ids=feed_ids, force=force)
|
||||||
|
|
||||||
social_feeds = {}
|
social_feeds = {}
|
||||||
if social_feed_ids:
|
if social_feed_ids:
|
||||||
|
|
|
@ -15,16 +15,18 @@ class MongoDumpMiddleware(object):
|
||||||
|
|
||||||
def process_view(self, request, callback, callback_args, callback_kwargs):
|
def process_view(self, request, callback, callback_args, callback_kwargs):
|
||||||
self._used_msg_ids = []
|
self._used_msg_ids = []
|
||||||
if settings.DEBUG:
|
if settings.DEBUG and not getattr(MongoClient, '_logging', False):
|
||||||
# save old methods
|
# save old methods
|
||||||
self.orig_send_message = \
|
setattr(MongoClient, '_logging', True)
|
||||||
MongoClient._send_message
|
# # save old methods
|
||||||
self.orig_send_message_with_response = \
|
# self.orig_send_message = \
|
||||||
MongoClient._send_message_with_response
|
# MongoClient._send_message
|
||||||
self.orig_rs_send_message = \
|
# self.orig_send_message_with_response = \
|
||||||
MongoReplicaSetClient._send_message
|
# MongoClient._send_message_with_response
|
||||||
self.orig_rs_send_message_with_response = \
|
# self.orig_rs_send_message = \
|
||||||
MongoReplicaSetClient._send_message_with_response
|
# MongoReplicaSetClient._send_message
|
||||||
|
# self.orig_rs_send_message_with_response = \
|
||||||
|
# MongoReplicaSetClient._send_message_with_response
|
||||||
# instrument methods to record messages
|
# instrument methods to record messages
|
||||||
MongoClient._send_message = \
|
MongoClient._send_message = \
|
||||||
self._instrument(MongoClient._send_message)
|
self._instrument(MongoClient._send_message)
|
||||||
|
@ -37,16 +39,16 @@ class MongoDumpMiddleware(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
if settings.DEBUG and hasattr(self, 'orig_send_message') and hasattr(self, 'orig_send_message_with_response'):
|
# if settings.DEBUG and hasattr(self, 'orig_send_message') and hasattr(self, 'orig_send_message_with_response'):
|
||||||
# remove instrumentation from pymongo
|
# # remove instrumentation from pymongo
|
||||||
MongoClient._send_message = \
|
# MongoClient._send_message = \
|
||||||
self.orig_send_message
|
# self.orig_send_message
|
||||||
MongoClient._send_message_with_response = \
|
# MongoClient._send_message_with_response = \
|
||||||
self.orig_send_message_with_response
|
# self.orig_send_message_with_response
|
||||||
MongoReplicaSetClient._send_message = \
|
# MongoReplicaSetClient._send_message = \
|
||||||
self.orig_rs_send_message
|
# self.orig_rs_send_message
|
||||||
MongoReplicaSetClient._send_message_with_response = \
|
# MongoReplicaSetClient._send_message_with_response = \
|
||||||
self.orig_rs_send_message_with_response
|
# self.orig_rs_send_message_with_response
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _instrument(self, original_method):
|
def _instrument(self, original_method):
|
||||||
|
|
|
@ -10,20 +10,22 @@ class RedisDumpMiddleware(object):
|
||||||
raise MiddlewareNotUsed()
|
raise MiddlewareNotUsed()
|
||||||
|
|
||||||
def process_view(self, request, callback, callback_args, callback_kwargs):
|
def process_view(self, request, callback, callback_args, callback_kwargs):
|
||||||
if settings.DEBUG:
|
if settings.DEBUG and not getattr(Connection, '_logging', False):
|
||||||
# save old methods
|
# save old methods
|
||||||
self.orig_pack_command = \
|
setattr(Connection, '_logging', True)
|
||||||
Connection.pack_command
|
# self.orig_pack_command = \
|
||||||
|
# Connection.pack_command
|
||||||
# instrument methods to record messages
|
# instrument methods to record messages
|
||||||
Connection.pack_command = \
|
Connection.pack_command = \
|
||||||
self._instrument(Connection.pack_command)
|
self._instrument(Connection.pack_command)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
if settings.DEBUG and hasattr(self, 'orig_pack_command'):
|
# if settings.DEBUG and hasattr(self, 'orig_pack_command'):
|
||||||
# remove instrumentation from redis
|
# # remove instrumentation from redis
|
||||||
Connection.pack_command = \
|
# setattr(Connection, '_logging', False)
|
||||||
self.orig_pack_command
|
# Connection.pack_command = \
|
||||||
|
# self.orig_pack_command
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _instrument(self, original_method):
|
def _instrument(self, original_method):
|
||||||
|
|
Loading…
Add table
Reference in a new issue