Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize iteration in DatasetInstance model + SA2.0 fix #16776

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4484,16 +4484,27 @@ def set_dbkey(self, value):
dbkey = property(get_dbkey, set_dbkey)

def ok_to_edit_metadata(self):
# prevent modifying metadata when dataset is queued or running as input/output
# This code could be more efficient, i.e. by using mappers, but to prevent slowing down loading a History panel, we'll leave the code here for now
sa_session = object_session(self)
for job_to_dataset_association in (
sa_session.query(JobToInputDatasetAssociation).filter_by(dataset_id=self.id).all()
+ sa_session.query(JobToOutputDatasetAssociation).filter_by(dataset_id=self.id).all()
):
if job_to_dataset_association.job.state not in Job.terminal_states:
return False
return True
"""
Prevent modifying metadata when dataset is queued or running as input/output:
return `False` if there exists an associated job with a non-terminal state.
"""

def exists_clause(assoc_model):
return (
select(assoc_model.job_id)
.join(Job)
.where(assoc_model.dataset_id == self.id)
.where(Job.state.not_in(Job.terminal_states))
.exists()
)

stmt = select(
or_(
exists_clause(JobToInputDatasetAssociation),
exists_clause(JobToOutputDatasetAssociation),
)
)
return not object_session(self).scalar(stmt)

def change_datatype(self, new_ext):
self.clear_associated_files()
Expand Down