mirror of https://github.com/zulip/zulip.git
populate_db: Fix inefficient pointer update at end of replay.
This cuts a 30s operation down to about 2s on my machine. And also move the code to run before we print the "done" message and have logging for how long it is taking. (imported from commit 2f20f8ca3fee714735a50fe6c6cfd630df452768)
This commit is contained in:
parent
156f6ee576
commit
a6f744a11f
|
@ -232,17 +232,6 @@ class Command(BaseCommand):
|
||||||
self.stdout.write("Successfully populated test database.\n")
|
self.stdout.write("Successfully populated test database.\n")
|
||||||
if options["replay_old_messages"]:
|
if options["replay_old_messages"]:
|
||||||
restore_saved_messages()
|
restore_saved_messages()
|
||||||
site = Site.objects.get_current()
|
|
||||||
site.domain = 'humbughq.com'
|
|
||||||
site.save()
|
|
||||||
|
|
||||||
# Set restored pointers to the very latest messages
|
|
||||||
for user_profile in UserProfile.objects.all():
|
|
||||||
ids = [u.message_id for u in UserMessage.objects.filter(user_profile = user_profile)]
|
|
||||||
if ids != []:
|
|
||||||
user_profile.pointer = max(ids)
|
|
||||||
user_profile.save()
|
|
||||||
|
|
||||||
|
|
||||||
recipient_hash = {}
|
recipient_hash = {}
|
||||||
def get_recipient_by_id(rid):
|
def get_recipient_by_id(rid):
|
||||||
|
@ -626,8 +615,23 @@ def restore_saved_messages():
|
||||||
print datetime.datetime.now(), "Finished importing %s messages (%s usermessages)" % \
|
print datetime.datetime.now(), "Finished importing %s messages (%s usermessages)" % \
|
||||||
(len(all_messages), tot_user_messages)
|
(len(all_messages), tot_user_messages)
|
||||||
|
|
||||||
# Clear the remainder of the line, using a terminal control code.
|
site = Site.objects.get_current()
|
||||||
sys.stderr.write('\rDone replaying old messages.\x1B[0K\n')
|
site.domain = 'humbughq.com'
|
||||||
|
site.save()
|
||||||
|
|
||||||
|
print datetime.datetime.now(), "Filling in user pointers..."
|
||||||
|
|
||||||
|
# Set restored pointers to the very latest messages
|
||||||
|
with transaction.commit_on_success():
|
||||||
|
for up in UserProfile.objects.all():
|
||||||
|
try:
|
||||||
|
top = UserMessage.objects.filter(user_profile_id=up.id).order_by("-message")[0]
|
||||||
|
user_profile.pointer = top.message_id
|
||||||
|
except IndexError:
|
||||||
|
user_profile.pointer = -1
|
||||||
|
user_profile.save()
|
||||||
|
|
||||||
|
print datetime.datetime.now(), "Done replaying old messages"
|
||||||
|
|
||||||
# Create some test messages, including:
|
# Create some test messages, including:
|
||||||
# - multiple streams
|
# - multiple streams
|
||||||
|
|
Loading…
Reference in New Issue