Skip to content

Commit

Permalink
Optimize iteration
Browse files Browse the repository at this point in the history
No need to make lists before iteration given possible early termination
  • Loading branch information
jdavcs committed Oct 2, 2023
1 parent 13d8342 commit 02d6b27
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from collections.abc import Callable
from datetime import timedelta
from enum import Enum
from itertools import chain
from string import Template
from typing import (
Any,
Expand Down Expand Up @@ -4487,10 +4488,9 @@ 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()
):
stmt1 = select(JobToInputDatasetAssociation).filter_by(dataset_id=self.id)
stmt2 = select(JobToOutputDatasetAssociation).filter_by(dataset_id=self.id)
for job_to_dataset_association in chain(sa_session.scalars(stmt1), sa_session.scalars(stmt2)):
if job_to_dataset_association.job.state not in Job.terminal_states:
return False
return True
Expand Down

0 comments on commit 02d6b27

Please sign in to comment.