Reduce DB calls when getting an image
Right now if you want to get a single image, two queries need to be executed: - Get image + associated locations and properties - Get associated tags for image Proposed solution combines these two queries into single one which gets image and all related data - locations, properties and tags. Similar pattern has been already implemented when querying for list of images. Change-Id: Ic4424bb1eb1769d8f621ebe111d95961ecf08479 Closes-Bug: 1434578
This commit is contained in:
@@ -380,7 +380,8 @@ def _sort_images(images, sort_key, sort_dir):
|
||||
return images
|
||||
|
||||
|
||||
def _image_get(context, image_id, force_show_deleted=False, status=None):
|
||||
def _image_get(context, image_id, force_show_deleted=False, status=None,
|
||||
return_tag=False):
|
||||
try:
|
||||
image = DATA['images'][image_id]
|
||||
except KeyError:
|
||||
@@ -396,12 +397,18 @@ def _image_get(context, image_id, force_show_deleted=False, status=None):
|
||||
LOG.warn(_LW('Unable to get unowned image'))
|
||||
raise exception.Forbidden("Image not visible to you")
|
||||
|
||||
if return_tag:
|
||||
image['tags'] = image_tag_get_all(context, image_id)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
@log_call
|
||||
def image_get(context, image_id, session=None, force_show_deleted=False):
|
||||
image = _image_get(context, image_id, force_show_deleted)
|
||||
def image_get(context, image_id, session=None, force_show_deleted=False,
|
||||
return_tag=False):
|
||||
image = _image_get(context, image_id, force_show_deleted,
|
||||
return_tag=return_tag)
|
||||
|
||||
return _normalize_locations(context, copy.deepcopy(image),
|
||||
force_show_deleted=force_show_deleted)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user