2013-08-01 20:36:42 +02:00
|
|
|
from __future__ import absolute_import
|
2015-11-01 17:11:06 +01:00
|
|
|
from __future__ import print_function
|
2013-08-01 20:36:42 +02:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2013-08-01 20:36:42 +02:00
|
|
|
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.
|
|
|
|
|
2016-04-07 15:27:25 +02:00
|
|
|
Usage: python manage.py render_old_messages"""
|
2013-08-01 20:36:42 +02:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **Any) -> None
|
2013-08-01 20:36:42 +02:00
|
|
|
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)
|
2015-11-01 17:11:06 +01:00
|
|
|
print(datetime.datetime.now(), total_rendered)
|
2013-08-01 20:36:42 +02:00
|
|
|
# Put in some sleep so this can run safely on low resource machines
|
|
|
|
time.sleep(0.25)
|