Is there any performance benefit to using bulk_update as compared to just update in django for a same value update?
I have the following piece of code
Subscription.objects.filter(id__in=[subscription.id for subscription in subscriptions]).update(renewal_notification_sent=True)
but I'm wondering if something like
updatable_subscriptions = []
subs = Subscription.objects.filter(id__in=[subscription.id for subscription in subscriptions])
for sub in subs:
sub.renewal_notification_sent = True
updatable_subscriptions.append(
subs
)
# then
Subscription.objects.bulk_update(updatable_subscriptions, ["renewal_notification_sent"])
would have any performance benefit. Does calling filter
followed by update
make 2 database queries?
filter followed by update make 2 queries. About performance, bulk_update does an sql update with case while update does a simple update behind the scenes, for bigger updates it's better use bulk_update.