Optimize blob lookup

Fixes #1013
This commit is contained in:
Joseph Schorr 2015-12-03 16:19:22 -05:00
parent 597d6ecd3c
commit f07b940bc5
3 changed files with 45 additions and 21 deletions

View file

@ -131,6 +131,15 @@ def _get_storage(query_modifier):
return found
def get_storage_by_subquery(subquery):
""" Returns the storage (and its locations) for the storage id returned by the subquery. The
subquery must return at most 1 result, which is a storage ID. """
def filter_by_subquery(query):
return query.where(ImageStorage.id == subquery)
return _get_storage(filter_by_subquery)
def get_storage_by_uuid(storage_uuid):
def filter_to_uuid(query):
return query.where(ImageStorage.uuid == storage_uuid)
@ -202,7 +211,7 @@ def get_storage_locations(uuid):
.select()
.join(ImageStorageLocation)
.switch(ImageStoragePlacement)
.join(ImageStorage, JOIN_LEFT_OUTER)
.join(ImageStorage)
.where(ImageStorage.uuid == uuid))
return [location.location.name for location in query]