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
|
|
|
|
|
2016-10-04 17:35:36 +02:00
|
|
|
import zerver.lib.bugdown as bugdown
|
|
|
|
from zerver.lib.message import re_render_content_for_management_command
|
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:
|
2016-10-04 17:35:36 +02:00
|
|
|
messages = Message.objects.exclude(rendered_content_version=bugdown.version)[0:100]
|
2013-08-01 20:36:42 +02:00
|
|
|
if len(messages) == 0:
|
|
|
|
break
|
|
|
|
for message in messages:
|
2016-10-04 17:35:36 +02:00
|
|
|
re_render_content_for_management_command(message)
|
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)
|