DB: Optimize update methods
Many of our resources' update methods read the resource from the DB, joining other tables in some cases, and then do the update using SQLAlchemy ORM engine before returning updated ORM object. There are some resources -volume_attachment, snapshot, backup, CG, CGSnapshot, qos_specs, volume_type, and group_type- that don't care about the updated ORM object, so we are actually doing unnecessary DB operations. This patch removes the unnecessary DB read operations when updating those resources. In the case of volume_type and group_type we are also retrieving a DB entry instead of doing an exists check to check if a name chage is valid. This patch also changes that check to the faster exists method. Change-Id: Ib6623fae5e31a81e032c3d429f6562cf2d13fb3e
This commit is contained in:
@@ -70,11 +70,9 @@ def update(context, id, name, description, is_public=None):
|
||||
elevated = context if context.is_admin else context.elevated()
|
||||
old_volume_type = get_volume_type(elevated, id)
|
||||
try:
|
||||
type_updated = db.volume_type_update(elevated,
|
||||
id,
|
||||
dict(name=name,
|
||||
description=description,
|
||||
is_public=is_public))
|
||||
db.volume_type_update(elevated, id,
|
||||
dict(name=name, description=description,
|
||||
is_public=is_public))
|
||||
# Rename resource in quota if volume type name is changed.
|
||||
if name:
|
||||
old_type_name = old_volume_type.get('name')
|
||||
@@ -85,7 +83,6 @@ def update(context, id, name, description, is_public=None):
|
||||
except db_exc.DBError:
|
||||
LOG.exception(_LE('DB error:'))
|
||||
raise exception.VolumeTypeUpdateFailed(id=id)
|
||||
return type_updated
|
||||
|
||||
|
||||
def destroy(context, id):
|
||||
|
||||
Reference in New Issue
Block a user