Merge pull request #927 from jakedt/alias

Alias our subqueries to appease the MySQL beast
This commit is contained in:
Jake Moshenko 2015-11-19 13:07:09 -05:00
commit bb934e04af

View file

@ -226,12 +226,14 @@ def lookup_repo_storages_by_content_checksum(repo, checksums):
# to use a union to select just one storage with each checksum
queries = []
for checksum in set(checksums):
for counter, checksum in enumerate(set(checksums)):
query_alias = 'q{0}'.format(counter)
candidate_subq = (ImageStorage
.select(ImageStorage.id, ImageStorage.content_checksum)
.join(Image)
.where(Image.repository == repo, ImageStorage.content_checksum == checksum)
.limit(1))
.limit(1)
.alias(query_alias))
queries.append(ImageStorage
.select(SQL('*'))
.from_(candidate_subq))