import: Fix bad database query for first_message_id.

The previous query ended up doing an awkward join that did not
guarantee use of the Recipient index on zerver_message, turning a very
fast query into something that could take much longer for a single
stream than the rest of the import combined.
This commit is contained in:
Tim Abbott 2019-06-18 10:25:00 -07:00
parent 5af8b980fe
commit 2538f84447
1 changed files with 2 additions and 3 deletions

View File

@ -1001,9 +1001,8 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int=1) -> Realm
# Similarly, we need to recalculate the first_message_id for stream objects.
for stream in Stream.objects.filter(realm=realm):
first_message = Message.objects.filter(
recipient__type_id=stream.id,
recipient__type=2).first()
recipient = Recipient.objects.get(type=Recipient.STREAM, type_id=stream.id)
first_message = Message.objects.filter(recipient=recipient).first()
if first_message is None:
stream.first_message_id = None
else: