Skip to content

Commit

Permalink
Add method to hda_repo; use in services.histories
Browse files Browse the repository at this point in the history
get_with_filter_order_by_hid
  • Loading branch information
jdavcs committed Aug 16, 2023
1 parent 7aa3786 commit 5136dd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/galaxy/model/repositories/hda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
List,
)

from sqlalchemy import select

from galaxy.model import HistoryDatasetAssociation
from galaxy.model.repositories import (
BaseRepository,
Expand All @@ -17,3 +19,10 @@ def __init__(self, session: SessionType):

def get(self, primary_key: int) -> HistoryDatasetAssociation: # type:ignore[override]
return cast(HistoryDatasetAssociation, super().get(primary_key))

def get_with_filter_order_by_hid(self, **kwd) -> List:
# type-ignore/SessionlessContext
stmt = (
select(self.model_class).filter_by(**kwd).order_by(self.model_class.hid.desc()) # type:ignore[attr-defined]
)
return self.session.scalars(stmt).all() # type:ignore[union-attr]
10 changes: 3 additions & 7 deletions lib/galaxy/webapps/galaxy/services/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from sqlalchemy import (
false,
select,
true,
)

Expand All @@ -42,6 +41,7 @@
from galaxy.managers.notification import NotificationManager
from galaxy.managers.users import UserManager
from galaxy.model.base import transaction
from galaxy.model.repositories.hda import HistoryDatasetAssociationRepository as hda_repo
from galaxy.model.store import payload_to_source_uri
from galaxy.schema import (
FilterQueryParams,
Expand Down Expand Up @@ -641,13 +641,9 @@ def get_custom_builds_metadata(
installed_builds = []
for build in glob.glob(os.path.join(trans.app.config.len_file_path, "*.len")):
installed_builds.append(os.path.basename(build).split(".len")[0])

stmt = (
select(model.HistoryDatasetAssociation)
.filter_by(history=history, extension="fasta", deleted=False)
.order_by(model.HistoryDatasetAssociation.hid.desc())
fasta_hdas = hda_repo(trans.sa_session).get_with_filter_order_by_hid(
history=history, extension="fasta", deleted=False
)
fasta_hdas = trans.sa_session.scalars(stmt)
return CustomBuildsMetadataResponse(
installed_builds=[LabelValuePair(label=ins, value=ins) for ins in installed_builds],
fasta_hdas=[
Expand Down

0 comments on commit 5136dd0

Please sign in to comment.