Skip to content

Commit

Permalink
Use transaction context instead of flush
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Feb 3, 2023
1 parent 2c02c7a commit 612b311
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
21 changes: 10 additions & 11 deletions lib/galaxy/managers/hdas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 10 additions & 11 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 612b311

Please sign in to comment.