MySQL still doesn't allow us to have empty IN clauses.

This commit is contained in:
Jake Moshenko 2014-10-17 17:49:18 -04:00
parent 6ca0115b5e
commit dc5ee43a3a

View file

@ -1423,18 +1423,20 @@ def garbage_collect_storage(storage_id_whitelist):
# Find out which derived storages will be removed, and add them to the whitelist # Find out which derived storages will be removed, and add them to the whitelist
orphaned_from_candidates = list(orphaned_storage_query(ImageStorage.select(ImageStorage.id), orphaned_from_candidates = list(orphaned_storage_query(ImageStorage.select(ImageStorage.id),
storage_id_whitelist)) storage_id_whitelist))
derived_to_remove = (ImageStorage
.select(ImageStorage.id)
.join(DerivedImageStorage,
on=(ImageStorage.id == DerivedImageStorage.derivative))
.where(DerivedImageStorage.source << orphaned_from_candidates))
storage_id_whitelist.update({derived.id for derived in derived_to_remove})
# Remove the dervived image storages with sources of orphaned storages if len(orphaned_from_candidates) > 0:
(DerivedImageStorage derived_to_remove = (ImageStorage
.delete() .select(ImageStorage.id)
.where(DerivedImageStorage.source << orphaned_from_candidates) .join(DerivedImageStorage,
.execute()) on=(ImageStorage.id == DerivedImageStorage.derivative))
.where(DerivedImageStorage.source << orphaned_from_candidates))
storage_id_whitelist.update({derived.id for derived in derived_to_remove})
# Remove the dervived image storages with sources of orphaned storages
(DerivedImageStorage
.delete()
.where(DerivedImageStorage.source << orphaned_from_candidates)
.execute())
# Track all of the data that should be removed from blob storage # Track all of the data that should be removed from blob storage
placements_to_remove = orphaned_storage_query(ImageStoragePlacement placements_to_remove = orphaned_storage_query(ImageStoragePlacement
@ -1448,18 +1450,21 @@ def garbage_collect_storage(storage_id_whitelist):
paths_to_remove = placements_query_to_paths_set(placements_to_remove.clone()) paths_to_remove = placements_query_to_paths_set(placements_to_remove.clone())
# Remove the placements for orphaned storages # Remove the placements for orphaned storages
placements_subquery = placements_to_remove.clone().select(ImageStoragePlacement.id) placements_subquery = list(placements_to_remove.clone().select(ImageStoragePlacement.id))
(ImageStoragePlacement if len(placements_subquery) > 0:
.delete() (ImageStoragePlacement
.where(ImageStoragePlacement.id << list(placements_subquery)) .delete()
.execute()) .where(ImageStoragePlacement.id << list(placements_subquery))
.execute())
# Remove the all orphaned storages # Remove the all orphaned storages
(ImageStorage orphaned_storages = list(orphaned_storage_query(ImageStorage.select(ImageStorage.id),
.delete() storage_id_whitelist))
.where(ImageStorage.id << list(orphaned_storage_query(ImageStorage.select(ImageStorage.id), if len(orphaned_storages) > 0:
storage_id_whitelist))) (ImageStorage
.execute()) .delete()
.where(ImageStorage.id << orphaned_storages)
.execute())
# Delete the actual blob storage # Delete the actual blob storage
for location_name, image_path in paths_to_remove: for location_name, image_path in paths_to_remove: