Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

bulk_update: Do updates in bulk where applicable.

Clara Dantasf26d0affefdf
diff --git a/zerver/lib/bulk_create.py b/zerver/lib/bulk_create.py
index eb37044502d..785afa8f4f6 100644
--- a/zerver/lib/bulk_create.py
+++ b/zerver/lib/bulk_create.py
@@ -90,14 +90,14 @@ def bulk_set_users_or_streams_recipient_fields(model: Model,
objects_dict = {obj.id: obj for obj in objects}
+ objects_to_update = set()
for recipient in recipients:
assert recipient.type == recipient_type
result = objects_dict.get(recipient.type_id)
if result is not None:
result.recipient = recipient
- # TODO: Django 2.2 has a bulk_update method, so once we manage to migrate to that version,
- # we take adventage of this, instead of calling save individually.
- result.save(update_fields=['recipient'])
+ objects_to_update.add(result)
+ model.objects.bulk_update(objects_to_update, ['recipient'])
# This is only sed in populate_db, so doesn't really need tests
def bulk_create_streams(realm: Realm,
diff --git a/zerver/management/commands/deliver_scheduled_messages.py b/zerver/management/commands/deliver_scheduled_messages.py
index f98a9ff9efa..bd50d3b8ba7 100644
--- a/zerver/management/commands/deliver_scheduled_messages.py
+++ b/zerver/management/commands/deliver_scheduled_messages.py
@@ -65,7 +65,7 @@ Usage: ./manage.py deliver_scheduled_messages
with transaction.atomic():
do_send_messages([self.construct_message(message)])
message.delivered = True
- message.save(update_fields=['delivered'])
+ Message.objects.bulk_update(messages_to_deliver, ['delivered'])
cur_time = timezone_now()
time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0)