mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
This saves something like 15ms on our 1000 message get_old_messages queries, and will save even more when we start sending JSON dumps into our memcached system. We need to install python-ujson on servers and dev instances before pushing this to prod. (imported from commit 373690b7c056d00d2299a7588a33f025104bfbca)
31 lines
1010 B
Python
31 lines
1010 B
Python
from __future__ import absolute_import
|
|
|
|
import time
|
|
import ujson
|
|
|
|
from collections import defaultdict
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.conf import settings
|
|
|
|
from zephyr.lib.queue import SimpleQueueClient
|
|
from zephyr.lib.actions import handle_missedmessage_emails
|
|
|
|
class Command(BaseCommand):
|
|
def handle(self, *args, **options):
|
|
q = SimpleQueueClient()
|
|
while True:
|
|
missed_events = q.drain_queue("missedmessage_emails", json=True)
|
|
by_recipient = defaultdict(list)
|
|
|
|
for event in missed_events:
|
|
print "Received missed message event: %s" % (event,)
|
|
by_recipient[event['user_profile_id']].append(event)
|
|
|
|
for user_profile_id, events in by_recipient.items():
|
|
handle_missedmessage_emails(user_profile_id, events)
|
|
|
|
# Aggregate all messages received every 2 minutes to let someone finish sending a batch
|
|
# of messages
|
|
time.sleep(2 * 60)
|