Don't perform an additional SELECT just to get a count for statsd.

len() uses the QuerySet as an iterator, which performs a SELECT for all
of those rows.

(imported from commit d362fef375c5270bedade2a7b50aea7b1a559d1e)
This commit is contained in:
Kevin Mehall
2013-06-25 14:26:50 -04:00
parent 953e195be1
commit a06860ca68

View File

@@ -846,11 +846,11 @@ def update_message_flags(user_profile, operation, flag, messages, all):
message__id__in=messages)
if operation == 'add':
msgs.update(flags=F('flags').bitor(flagattr))
count = msgs.update(flags=F('flags').bitor(flagattr))
elif operation == 'remove':
msgs.update(flags=F('flags').bitand(~flagattr))
count = msgs.update(flags=F('flags').bitand(~flagattr))
statsd.incr("flags.%s.%s" % (flag, operation), len(msgs))
statsd.incr("flags.%s.%s" % (flag, operation), count)
def process_user_presence_event(event):
user_profile = get_user_profile_by_id(event["user_profile_id"])