diff options
author | Boris Pavlovic <boris@pavlovic.me> | 2012-12-17 13:50:18 +0400 |
---|---|---|
committer | Boris Pavlovic <boris@pavlovic.me> | 2013-01-06 01:21:24 +0400 |
commit | 36df7fa38cbd0c991c8df2f9f6c8220e2b164394 (patch) | |
tree | c8454b7e8551305034e44b6461f88e6db51e1099 | |
parent | cd0f02113110bdc25eea4f57db640e906636c814 (diff) | |
download | nova-36df7fa38cbd0c991c8df2f9f6c8220e2b164394.tar.gz nova-36df7fa38cbd0c991c8df2f9f6c8220e2b164394.tar.xz nova-36df7fa38cbd0c991c8df2f9f6c8220e2b164394.zip |
NovaBase.delete() rename to NovaBase.soft_delete()
Name of this method is misleading. This method actually does not delete entry
from DB instead of that it only marks entry as deleted as well as
query.soft_delete(). Furthermore we have query.delete() that deletes from DB
all matched entries. So it is very important to rename this method to avoid
misunderstanding.
blueprint db-session-cleanup
Change-Id: Ic8b92ce1c087794aca4faafa9c68c72d444e5f9e
-rw-r--r-- | nova/db/sqlalchemy/api.py | 4 | ||||
-rw-r--r-- | nova/db/sqlalchemy/models.py | 4 | ||||
-rw-r--r-- | nova/db/sqlalchemy/session.py | 16 |
3 files changed, 12 insertions, 12 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index dce92ba54..d70522d73 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -298,12 +298,12 @@ def service_destroy(context, service_id): session = get_session() with session.begin(): service_ref = service_get(context, service_id, session=session) - service_ref.delete(session=session) + service_ref.soft_delete(session=session) if (service_ref.topic == CONF.compute_topic and service_ref.compute_node): for c in service_ref.compute_node: - c.delete(session=session) + c.soft_delete(session=session) @require_admin_context diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index c7e956a40..cdd140b6e 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -51,8 +51,8 @@ class NovaBase(object): session.add(self) session.flush() - def delete(self, session=None): - """Delete this object.""" + def soft_delete(self, session=None): + """Mark this object as deleted.""" self.deleted = True self.deleted_at = timeutils.utcnow() self.save(session=session) diff --git a/nova/db/sqlalchemy/session.py b/nova/db/sqlalchemy/session.py index ae8fec32d..adfc39517 100644 --- a/nova/db/sqlalchemy/session.py +++ b/nova/db/sqlalchemy/session.py @@ -162,9 +162,9 @@ There are some things which it is best to avoid: Efficient use of soft deletes: * There are two possible ways to mark a record as deleted: - model.delete() and query.soft_delete(). + model.soft_delete() and query.soft_delete(). - model.delete() method works with single already fetched entry. + model.soft_delete() method works with single already fetched entry. query.soft_delete() makes only one db request for all entries that correspond to query. @@ -187,8 +187,8 @@ Efficient use of soft deletes: if count == 0: raise Exception("0 entries were soft deleted") -* There is only one situation where model.delete is appropriate: when you fetch - a single record, work with it, and mark it as deleted in the same +* There is only one situation where model.soft_delete() is appropriate: when + you fetch a single record, work with it, and mark it as deleted in the same transaction. def soft_delete_bar_model(): @@ -196,7 +196,7 @@ Efficient use of soft deletes: with session.begin(): bar_ref = model_query(BarModel).find(some_condition).first() # Work with bar_ref - bar_ref.delete(session=session) + bar_ref.soft_delete(session=session) However, if you need to work with all entries that correspond to query and then soft delete them you should use query.soft_delete() method: @@ -213,11 +213,11 @@ Efficient use of soft deletes: # session and these entries are not used after this. When working with many rows, it is very important to use query.soft_delete, - which issues a single query. Using model.delete, as in the following example, - is very inefficient. + which issues a single query. Using model.soft_delete(), as in the following + example, is very inefficient. for bar_ref in bar_refs: - bar_ref.delete(session=session) + bar_ref.soft_delete(session=session) # This will produce count(bar_refs) db requests. """ |