django-easy-audit icon indicating copy to clipboard operation
django-easy-audit copied to clipboard

Avoid DB savepoints if no audit is going to be created

Open hugobranquinho opened this issue 3 years ago • 2 comments
trafficstars

If we save a model with a db transaction and that model don't have audit active, it's making unnecessary db calls:

SAVEPOINT "xpto_x1";
RELEASE SAVEPOINT "xpto_x1";

This happens because django creates a save point if a transaction is open inside another transaction. To avoid it, and save some db calls, do should_audit(instance) before creating transaction.atomic.

hugobranquinho avatar Jun 06 '22 21:06 hugobranquinho

So I do agree that if we can avoid certain paths in the flow, we should, and I'm still concurring that this is a good change, but is it actually hitting the database in the situations where the audit isn't going to be performed? Or is it more that we're looking to avoid needless extra (or any at all) db save points in the current transaction?

jheld avatar Jun 30 '22 20:06 jheld

@jheld Yup, is hitting the db to create and release the save point (2 db queries) Because on my project we don't have audit for all tables (i think we have more without audit) every change we do on those, we have 2 extra queries. For example, if we make 50 object updates and none of those have audit, we have 150 db calls.

hugobranquinho avatar Jul 01 '22 15:07 hugobranquinho