From a9667d81a8a22d02a3cc008dffae82c61ffc2b47 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 22 Oct 2012 22:01:55 -0400 Subject: [PATCH] Fix performance regression caused by last commit. (imported from commit f0abf93dbab92c5627903284fafad310de039fe6) --- zephyr/management/commands/populate_db.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zephyr/management/commands/populate_db.py b/zephyr/management/commands/populate_db.py index ec9a90dcbd..5f8a98ce25 100644 --- a/zephyr/management/commands/populate_db.py +++ b/zephyr/management/commands/populate_db.py @@ -421,7 +421,11 @@ def restore_saved_messages(): # Finally, create all the UserMessage objects print datetime.datetime.now(), "Importing usermessages, part 1..." - all_messages = Message.objects.select_related().all() + personal_recipients = {} + for r in Recipient.objects.filter(type = Recipient.PERSONAL): + personal_recipients[r.id] = True + + all_messages = Message.objects.all() user_messages_to_create = [] messages_by_id = {} @@ -461,7 +465,7 @@ def restore_saved_messages(): um = UserMessage(user_profile=users_by_id[user_profile_id], message=message) user_messages_to_create.append(um) - if message.recipient.type == Recipient.PERSONAL: + if message.recipient_id in personal_recipients: # Include the sender in huddle recipients um = UserMessage(user_profile=users_by_id[message.sender_id], message=message)