Strategies for speeding up batch ORM operations in Django

One of my API calls can result in updates to a large number of objects (Django models). I'm running into performance issues with this since I'm updating each item individually, saving, and moving on to the next:

for item in Something.objects.filter(x='y'):
    item.a="something"
    item.save()

Sometimes my filter criterion looks like "where x in ('a','b','c',...)".

It seems the official answer to this is "won't fix". I'm wondering what strategies people are using to improve performance in these scenarios.

Answers


The ticket you linked to is for bulk creation - if you're not relying on an overridden save method or pre/post save signals to do bits of work on save, QuerySet has an update method which you can use to perform an UPDATE on the filtered rows:

Something.objects.filter(x__in=['a', 'b', 'c']).update(a='something')

Need Your Help

Is there a simple Linq to SQL generator with bi-directional serialization attributes?

linq-to-sql serialization code-generation

I'm trying to find a way to generate Linq to SQL classes with bi-directional serialization attributes. Basically I want a DataMember tag (with an appropriate order) on every association property, not

If my “Then I should see” Cucumber feature is failing, how can I see what Cucumber is seeing?

ruby-on-rails cucumber

Presumably if Cucumber is not seeing what I expect it to see, it must be seeing something else. Mirroring in my application what I think the same steps are, I get the desired output.