MySQL doesnt allow us to use the table we are modifying in a subquery.
This commit is contained in:
parent
efe8825a15
commit
6ca0115b5e
1 changed files with 7 additions and 6 deletions
|
@ -1421,18 +1421,19 @@ def garbage_collect_storage(storage_id_whitelist):
|
|||
logger.debug('Garbage collecting storage from candidates: %s', storage_id_whitelist)
|
||||
with config.app_config['DB_TRANSACTION_FACTORY'](db):
|
||||
# Find out which derived storages will be removed, and add them to the whitelist
|
||||
orphaned_from_candidates = orphaned_storage_query(ImageStorage.select(), storage_id_whitelist)
|
||||
orphaned_from_candidates = list(orphaned_storage_query(ImageStorage.select(ImageStorage.id),
|
||||
storage_id_whitelist))
|
||||
derived_to_remove = (ImageStorage
|
||||
.select(ImageStorage.id)
|
||||
.join(DerivedImageStorage,
|
||||
on=(ImageStorage.id == DerivedImageStorage.derivative))
|
||||
.where(DerivedImageStorage.source << orphaned_from_candidates.clone()))
|
||||
.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.clone())
|
||||
.where(DerivedImageStorage.source << orphaned_from_candidates)
|
||||
.execute())
|
||||
|
||||
# Track all of the data that should be removed from blob storage
|
||||
|
@ -1450,14 +1451,14 @@ def garbage_collect_storage(storage_id_whitelist):
|
|||
placements_subquery = placements_to_remove.clone().select(ImageStoragePlacement.id)
|
||||
(ImageStoragePlacement
|
||||
.delete()
|
||||
.where(ImageStoragePlacement.id << placements_subquery)
|
||||
.where(ImageStoragePlacement.id << list(placements_subquery))
|
||||
.execute())
|
||||
|
||||
# Remove the all orphaned storages
|
||||
(ImageStorage
|
||||
.delete()
|
||||
.where(ImageStorage.id << orphaned_storage_query(ImageStorage.select(ImageStorage.id),
|
||||
storage_id_whitelist))
|
||||
.where(ImageStorage.id << list(orphaned_storage_query(ImageStorage.select(ImageStorage.id),
|
||||
storage_id_whitelist)))
|
||||
.execute())
|
||||
|
||||
# Delete the actual blob storage
|
||||
|
|
Reference in a new issue