mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	Add a management command to render all old messages.
I'd like to minimize the probability that we'll actually run the code in the "messages not rendered yet in database" codepath since it might perform poorly, and it seems like the best way to do that is to just run a loop that renders them all. (imported from commit 247cb85fffa6cbc95958b9feda97462792a542c2)
This commit is contained in:
		
							
								
								
									
										26
									
								
								zephyr/management/commands/render_old_messages.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								zephyr/management/commands/render_old_messages.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
from __future__ import absolute_import
 | 
			
		||||
 | 
			
		||||
from django.core.management.base import BaseCommand
 | 
			
		||||
 | 
			
		||||
from zephyr.lib.actions import update_message_flags
 | 
			
		||||
from zephyr.models import UserProfile, Message, get_user_profile_by_email
 | 
			
		||||
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:
 | 
			
		||||
                message.maybe_render_content(save=True)
 | 
			
		||||
            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)
 | 
			
		||||
		Reference in New Issue
	
	Block a user