python - Aggregating save()s in Django? -


I am using Django with a SQL backend, and writing is a problem. I can be a graduate of "proper" DB at some level, but at this time I have stayed with the scalet. I think my writing problems are probably related to the fact that I am making a large number of rows, and possibly : Every time I save () one locking it, unlocking and syncing DB to disk.

How do I collect a large number of save () calls in a single database operation?

Actually it's easy to do, then you think. You can use these batch database operations in Django (especially save, insert and delete) in an operation. I've found that the easiest way is to commit_on_success . Basically you save your database to a function and then use the commit_on_success decorator. Django.db.transaction import commit_on_success @commit_on_success def from lot_of_saves (queryset): In query for items: modify_item (item) item.save ()

If any of the items are unsuccessful, you will also get the benefit of making a roll back if you have saved millions of operations, then you have them commit_manually and transaction.commit () , but I rarely need it.

Hope that helps,

will


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -