2013-08-01 20:36:42 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
|
2013-11-04 17:22:58 +01:00
|
|
|
from zerver.models import Message
|
2013-08-01 20:36:42 +02:00
|
|
|
import datetime
|
|
|
|
import time
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = """Render all historical messages that haven't been rendered yet.
|
|
|
|
|
|
|
|
Usage: python manage.py render_old_messages"""
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
total_rendered = 0
|
|
|
|
while True:
|
|
|
|
messages = Message.objects.filter(rendered_content_version=None)[0:100]
|
|
|
|
if len(messages) == 0:
|
|
|
|
break
|
|
|
|
for message in messages:
|
2013-09-04 22:44:45 +02:00
|
|
|
message.maybe_render_content(None, save=True)
|
2013-08-01 20:36:42 +02:00
|
|
|
total_rendered += len(messages)
|
|
|
|
print datetime.datetime.now(), total_rendered
|
|
|
|
# Put in some sleep so this can run safely on low resource machines
|
|
|
|
time.sleep(0.25)
|