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 7, 2023
1 parent d232e8c commit 1bfdbf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 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
22 changes: 10 additions & 12 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@


class HistoryManager(sharable.SharableModelManager, deletable.PurgableManagerMixin, SortableManager):

model_class = model.History
foreign_key_name = "history"
user_share_model = model.HistoryUserShareAssociation
Expand Down Expand Up @@ -415,17 +414,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 1bfdbf8

Please sign in to comment.