From 5136dd01c817e3b9a9dd5aad1e76c46f05ef40d6 Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 15 Aug 2023 14:53:19 -0400 Subject: [PATCH] Add method to hda_repo; use in services.histories get_with_filter_order_by_hid --- lib/galaxy/model/repositories/hda.py | 9 +++++++++ lib/galaxy/webapps/galaxy/services/histories.py | 10 +++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/model/repositories/hda.py b/lib/galaxy/model/repositories/hda.py index 900927b62f16..9de7c5de6672 100644 --- a/lib/galaxy/model/repositories/hda.py +++ b/lib/galaxy/model/repositories/hda.py @@ -3,6 +3,8 @@ List, ) +from sqlalchemy import select + from galaxy.model import HistoryDatasetAssociation from galaxy.model.repositories import ( BaseRepository, @@ -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] diff --git a/lib/galaxy/webapps/galaxy/services/histories.py b/lib/galaxy/webapps/galaxy/services/histories.py index 99a1a262aa66..4f47aef4eb9a 100644 --- a/lib/galaxy/webapps/galaxy/services/histories.py +++ b/lib/galaxy/webapps/galaxy/services/histories.py @@ -16,7 +16,6 @@ from sqlalchemy import ( false, - select, true, ) @@ -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, @@ -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=[