diff options
author | Boris Pavlovic <boris@pavlovic.me> | 2012-12-19 14:21:01 +0400 |
---|---|---|
committer | Boris Pavlovic <boris@pavlovic.me> | 2012-12-22 01:48:36 +0400 |
commit | eda851676d14956c03616e5b2cb856acdc8edbef (patch) | |
tree | 64854cb36789def9db6bcfb1ffc6849b3016d3c3 /nova/exception.py | |
parent | 3f1a70bdb1b2a7df7147f09e2b0b09dd1b49f3be (diff) | |
download | nova-eda851676d14956c03616e5b2cb856acdc8edbef.tar.gz nova-eda851676d14956c03616e5b2cb856acdc8edbef.tar.xz nova-eda851676d14956c03616e5b2cb856acdc8edbef.zip |
Create and use subclass of sqlalchemy Query with soft_delete() method
Create subclass of sqlalchemy.orm.query.Query that has soft_delete() method
Change get_maker() method to create Session with our Query class
The main idea of soft_delete() method is to get good performance with clean
syntax: Let we have already `query` instance.
Clean syntax example:
If we want to make soft delete for each entry that correspond to query:
we should write:
query.soft_delete()
instead of:
query.update({
deleted:True,
'deleted_at': timeutils.utcnow(),
'updated_at': literal_column('updated_at')})
Performance examples:
If we make:
query.soft_delete()
we will make only one request to soft delete corresponding entries.
But if we make:
for model_ref in query.all():
model_ref.delete(session=session)
it will produce >= N + 1 queries.
In almost all situation it is better to use query.soft_delete() than
model.delete() method, because in second approach we should make
2 request (get model_ref and then soft delete it).
In future patch model.delete() will be at least renamed to model.soft_delete().
Probably it should be removed at all, to avoid situation in code with N+1
requests for soft deletion.
blueprint db-session-cleanup
Change-Id: I6059982b83648133b6d8becf94ad8980b056c6ff
Diffstat (limited to 'nova/exception.py')
0 files changed, 0 insertions, 0 deletions