From 612b3118c359fef1e2d768945bb320d363c7c8e0 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Tue, 31 Jan 2023 13:08:08 +0100 Subject: [PATCH] Use transaction context instead of flush --- lib/galaxy/managers/hdas.py | 21 ++++++++++----------- lib/galaxy/managers/histories.py | 21 ++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/galaxy/managers/hdas.py b/lib/galaxy/managers/hdas.py index 20dc40cd953f..a3bd74db8716 100644 --- a/lib/galaxy/managers/hdas.py +++ b/lib/galaxy/managers/hdas.py @@ -406,17 +406,16 @@ def cleanup_items(self, user: model.User, item_ids: Set[int]) -> StorageItemsCle total_free_bytes = 0 errors: List[StorageItemCleanupError] = [] - for hda_id in item_ids: - try: - hda = self.hda_manager.get_owned(hda_id, user) - self.hda_manager.purge(hda) - success_item_count += 1 - total_free_bytes += int(hda.get_size()) - except BaseException as e: - errors.append(StorageItemCleanupError(item_id=hda_id, error=str(e))) - - if success_item_count: - self.hda_manager.session().flush() + with self.hda_manager.session().begin(): + for hda_id in item_ids: + try: + hda = self.hda_manager.get_owned(hda_id, user) + self.hda_manager.purge(hda) + success_item_count += 1 + total_free_bytes += int(hda.get_size()) + except BaseException as e: + errors.append(StorageItemCleanupError(item_id=hda_id, error=str(e))) + return StorageItemsCleanupResult( total_item_count=len(item_ids), success_item_count=success_item_count, diff --git a/lib/galaxy/managers/histories.py b/lib/galaxy/managers/histories.py index 9aa5868720a6..98be1ed04880 100644 --- a/lib/galaxy/managers/histories.py +++ b/lib/galaxy/managers/histories.py @@ -415,17 +415,16 @@ def cleanup_items(self, user: model.User, item_ids: Set[int]) -> StorageItemsCle total_free_bytes = 0 errors: List[StorageItemCleanupError] = [] - for history_id in item_ids: - try: - history = self.history_manager.get_owned(history_id, user) - self.history_manager.purge(history, flush=False) - success_item_count += 1 - total_free_bytes += int(history.disk_size) - except BaseException as e: - errors.append(StorageItemCleanupError(item_id=history_id, error=str(e))) - - if success_item_count: - self.history_manager.session().flush() + with self.history_manager.session().begin(): + for history_id in item_ids: + try: + history = self.history_manager.get_owned(history_id, user) + self.history_manager.purge(history, flush=False) + success_item_count += 1 + total_free_bytes += int(history.disk_size) + except BaseException as e: + errors.append(StorageItemCleanupError(item_id=history_id, error=str(e))) + return StorageItemsCleanupResult( total_item_count=len(item_ids), success_item_count=success_item_count,