I have some database speed issues when doing an update with Django.
My request takes about 15s to be executed, updating ~1000 rows, which is quite slow
Here is a simplified version of my code
constant1 = sth
constant2 = sth
myList = Model.objects.filter(
...
)[:nb]
myListIds = []
for object in myList:
...
myListIds.append(object.pk)
Model.objects.filter(
pk__in=myListIds
).update(
...
field1 = constant1,
field2 = constant2,
...
)
I tried to look at the SQL request generated by Django, but it didn't teach me anything
What am I doing wrong here ?
My guess is that pk__in is the issue, but I can't find a workaround. I need to use a list of ids in order to update because my queryset is sliced, and Django does not allow to update sliced queryset (Cannot update a query once a slice has been taken.)