mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 20:13:46 +00:00 
			
		
		
		
	bulk_update: Do updates in bulk where applicable.
This commit is contained in:
		| @@ -90,14 +90,14 @@ def bulk_set_users_or_streams_recipient_fields(model: Model, | |||||||
|  |  | ||||||
|     objects_dict = {obj.id: obj for obj in objects} |     objects_dict = {obj.id: obj for obj in objects} | ||||||
|  |  | ||||||
|  |     objects_to_update = set() | ||||||
|     for recipient in recipients: |     for recipient in recipients: | ||||||
|         assert recipient.type == recipient_type |         assert recipient.type == recipient_type | ||||||
|         result = objects_dict.get(recipient.type_id) |         result = objects_dict.get(recipient.type_id) | ||||||
|         if result is not None: |         if result is not None: | ||||||
|             result.recipient = recipient |             result.recipient = recipient | ||||||
|             # TODO: Django 2.2 has a bulk_update method, so once we manage to migrate to that version, |             objects_to_update.add(result) | ||||||
|             # we take adventage of this, instead of calling save individually. |     model.objects.bulk_update(objects_to_update, ['recipient']) | ||||||
|             result.save(update_fields=['recipient']) |  | ||||||
|  |  | ||||||
| # This is only sed in populate_db, so doesn't really need tests | # This is only sed in populate_db, so doesn't really need tests | ||||||
| def bulk_create_streams(realm: Realm, | def bulk_create_streams(realm: Realm, | ||||||
|   | |||||||
| @@ -65,7 +65,7 @@ Usage: ./manage.py deliver_scheduled_messages | |||||||
|                     with transaction.atomic(): |                     with transaction.atomic(): | ||||||
|                         do_send_messages([self.construct_message(message)]) |                         do_send_messages([self.construct_message(message)]) | ||||||
|                         message.delivered = True |                         message.delivered = True | ||||||
|                         message.save(update_fields=['delivered']) |                 Message.objects.bulk_update(messages_to_deliver, ['delivered']) | ||||||
|  |  | ||||||
|             cur_time = timezone_now() |             cur_time = timezone_now() | ||||||
|             time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0) |             time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user