Skip to content

Commit

Permalink
Merge pull request #18970 from arash77/optimize_history_create
Browse files Browse the repository at this point in the history
Optimize to_history_dataset_association in create_datasets_from_library_folder
  • Loading branch information
jdavcs authored Oct 11, 2024
2 parents 6dc681d + 4bf029b commit 1eac67a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
13 changes: 9 additions & 4 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6048,7 +6048,9 @@ def __init__(
self.library_dataset = library_dataset
self.user = user

def to_history_dataset_association(self, target_history, parent_id=None, add_to_history=False, visible=None):
def to_history_dataset_association(
self, target_history, parent_id=None, add_to_history=False, visible=None, commit=True
):
sa_session = object_session(self)
hda = HistoryDatasetAssociation(
name=self.name,
Expand All @@ -6072,9 +6074,12 @@ def to_history_dataset_association(self, target_history, parent_id=None, add_to_
sa_session.add(hda)
hda.metadata = self.metadata
if add_to_history and target_history:
target_history.add_dataset(hda)
with transaction(sa_session):
sa_session.commit()
target_history.stage_addition(hda)
if commit:
target_history.add_pending_items()
if commit:
with transaction(sa_session):
sa_session.commit()
return hda

def copy(self, parent_id=None, target_folder=None, flush=True):
Expand Down
20 changes: 13 additions & 7 deletions lib/galaxy/webapps/galaxy/services/history_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,22 +1172,28 @@ def traverse(folder):
rval.append(ld)
return rval

for ld in traverse(folder):
hda = ld.library_dataset_dataset_association.to_history_dataset_association(
history, add_to_history=True
hdas = [
ld.library_dataset_dataset_association.to_history_dataset_association(
history, add_to_history=True, commit=False
)
for ld in traverse(folder)
]
history.add_pending_items()

with transaction(trans.sa_session):
trans.sa_session.commit()

for hda in hdas:
hda_dict = self.hda_serializer.serialize_to_view(
hda, user=trans.user, trans=trans, encode_id=False, **serialization_params.model_dump()
)
rval.append(hda_dict)
return rval

else:
message = f"Invalid 'source' parameter in request: {source}"
raise exceptions.RequestParameterInvalidException(message)

with transaction(trans.sa_session):
trans.sa_session.commit()
return rval

def __create_dataset(
self,
trans,
Expand Down

0 comments on commit 1eac67a

Please sign in to comment.