From 6d3ade93dd210a6d137e00609773b5a8807e8d24 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 15:48:26 -0500 Subject: [PATCH 01/16] Join/load: replace strings with attrs; use chaining (model) --- lib/galaxy/model/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 29af9c116d7e..f53a3febb670 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2962,10 +2962,10 @@ def active_dataset_and_roles_query(self): .filter(not_(HistoryDatasetAssociation.deleted)) .order_by(HistoryDatasetAssociation.table.c.hid.asc()) .options( - joinedload("dataset"), - joinedload("dataset.actions"), - joinedload("dataset.actions.role"), - joinedload("tags"), + joinedload(HistoryDatasetAssociation.dataset) + .joinedload(Dataset.actions) + .joinedload(DatasetPermissions.role), + joinedload(HistoryDatasetAssociation.tags), ) ) From aa24b9560fa717269ce5250e46f8f46e902be9c2 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 18:01:38 -0500 Subject: [PATCH 02/16] Join/load: replace strings with attrs (model) --- lib/galaxy/model/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index f53a3febb670..bda53e4dc969 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2993,7 +2993,10 @@ def active_visible_dataset_collections(self): .filter(not_(HistoryDatasetCollectionAssociation.deleted)) .filter(HistoryDatasetCollectionAssociation.visible) .order_by(HistoryDatasetCollectionAssociation.table.c.hid.asc()) - .options(joinedload("collection"), joinedload("tags")) + .options( + joinedload(HistoryDatasetCollectionAssociation.collection), + joinedload(HistoryDatasetCollectionAssociation.tags), + ) ) self._active_visible_dataset_collections = query.all() return self._active_visible_dataset_collections From da9b431d5c030f3d4ecbd217e835a45405871984 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 20:21:22 -0500 Subject: [PATCH 03/16] Join/load: replace strings with attrs (model.security) --- lib/galaxy/model/security.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/model/security.py b/lib/galaxy/model/security.py index 29159b70d0e9..881e3276bf47 100644 --- a/lib/galaxy/model/security.py +++ b/lib/galaxy/model/security.py @@ -1507,12 +1507,15 @@ def check_folder_contents(self, user, roles, folder, hidden_folder_ids=""): return True, "" action = self.permitted_actions.DATASET_ACCESS + raise lddas = ( self.sa_session.query(self.model.LibraryDatasetDatasetAssociation) .join("library_dataset") .filter(self.model.LibraryDataset.folder == folder) .join("dataset") - .options(joinedload("dataset").joinedload("actions")) + .options( + joinedload(self.model.LibraryDatasetDatasetAssociation.dataset).joinedload(self.model.Dataset.actions) + ) .all() ) From 6b063c396433f301445f94e15c297ba3b42f9404 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 21:02:25 -0500 Subject: [PATCH 04/16] Join/load: replace strings with attrs (managers.history_contents) --- lib/galaxy/managers/history_contents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/managers/history_contents.py b/lib/galaxy/managers/history_contents.py index 055a8b94687b..077b8fff1fdf 100644 --- a/lib/galaxy/managers/history_contents.py +++ b/lib/galaxy/managers/history_contents.py @@ -438,7 +438,7 @@ def _contained_id_map(self, id_list): .query(component_class) .filter(component_class.id.in_(id_list)) .options(undefer(component_class._metadata)) - .options(joinedload("dataset.actions")) # TODO: use class attr after moving Dataset to declarative mapping. + .options(joinedload(component_class.dataset).joinedload(model.Dataset.actions)) .options(joinedload(component_class.tags)) .options(joinedload(component_class.annotations)) # type: ignore[attr-defined] ) From e07d390db939c14b65fba9563fb29b50b8ae7805 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 21:05:29 -0500 Subject: [PATCH 05/16] Join/load: replace strings with attrs (tools.actions.upload_common) --- lib/galaxy/tools/actions/upload_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tools/actions/upload_common.py b/lib/galaxy/tools/actions/upload_common.py index 94f752c8faf7..412e83d0b548 100644 --- a/lib/galaxy/tools/actions/upload_common.py +++ b/lib/galaxy/tools/actions/upload_common.py @@ -422,10 +422,11 @@ def active_folders(trans, folder): # Stolen from galaxy.web.controllers.library_common (importing from which causes a circular issues). # Much faster way of retrieving all active sub-folders within a given folder than the # performance of the mapper. This query also eagerloads the permissions on each folder. + raise return ( trans.sa_session.query(LibraryFolder) .filter_by(parent=folder, deleted=False) - .options(joinedload("actions")) + .options(joinedload(LibraryFolder.actions)) .order_by(LibraryFolder.table.c.name) .all() ) From a1fa4ee817adb96ebb76e1d6c3d0da6fa33fe028 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 21:11:45 -0500 Subject: [PATCH 06/16] Join/load: replace strings with attrs (managers.session) --- lib/galaxy/managers/session.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/managers/session.py b/lib/galaxy/managers/session.py index 5d9fc238af81..4f6ca157f0ec 100644 --- a/lib/galaxy/managers/session.py +++ b/lib/galaxy/managers/session.py @@ -30,7 +30,7 @@ def get_session_from_session_key(self, session_key: str): self.model.GalaxySession.table.c.is_valid == true(), ) ) - .options(joinedload("user")) + .options(joinedload(self.model.GalaxySession.user)) .first() ) return galaxy_session From bacd49f26ecadc6663bcae90056698c33fa4edf1 Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 21:13:31 -0500 Subject: [PATCH 07/16] Join/load: replace strings with attrs (webapps.reports...) --- lib/galaxy/webapps/reports/controllers/system.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/webapps/reports/controllers/system.py b/lib/galaxy/webapps/reports/controllers/system.py index 0c8bfbe63ee3..e26446c75d2d 100644 --- a/lib/galaxy/webapps/reports/controllers/system.py +++ b/lib/galaxy/webapps/reports/controllers/system.py @@ -115,7 +115,7 @@ def deleted_histories(self, trans, **kwd): model.History.update_time < cutoff_time, ) ) - .options(joinedload("datasets")) + .options(joinedload(model.History.datasets)) ) for history in histories: From dcb481eeb0e531e65cd5b28523ceef1bdb1388bb Mon Sep 17 00:00:00 2001 From: John Davis Date: Thu, 19 Jan 2023 22:02:04 -0500 Subject: [PATCH 08/16] Join/load: replace strings with attrs (webapps...controllers.workflow) --- lib/galaxy/webapps/galaxy/controllers/workflow.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/workflow.py b/lib/galaxy/webapps/galaxy/controllers/workflow.py index 3e51a7d83082..8c8038c6384f 100644 --- a/lib/galaxy/webapps/galaxy/controllers/workflow.py +++ b/lib/galaxy/webapps/galaxy/controllers/workflow.py @@ -163,12 +163,12 @@ def build_initial_query(self, trans, **kwargs): # of its steps to be eagerly loaded. return ( trans.sa_session.query(self.model_class) - .join("user") + .join(self.model_class.user) .options( - lazyload("latest_workflow"), - joinedload("user").load_only("username"), - joinedload("annotations"), - undefer("average_rating"), + lazyload(self.model_class.latest_workflow), + joinedload(self.model_class.user).load_only(model.User.username), + joinedload(self.model_class.annotations), + undefer(self.model_class.average_rating), ) ) @@ -487,7 +487,7 @@ def editor(self, trans, id=None, workflow_id=None, version=None): trans.sa_session.query(model.StoredWorkflow) .filter_by(user=trans.user, deleted=False, hidden=False) .order_by(desc(model.StoredWorkflow.table.c.update_time)) - .options(joinedload("latest_workflow").joinedload("steps")) + .options(joinedload(model.StoredWorkflow.latest_workflow).joinedload(model.Workflow.steps)) .all() ) if version is None: From f8567642ee8d4cf934bf488c79d466789fd33e7c Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:04:44 -0500 Subject: [PATCH 09/16] Join/load: replace strings with attrs (managers.workflows) --- lib/galaxy/managers/workflows.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index b1fd01a565a5..9e2e011bf779 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -163,10 +163,10 @@ def index_query( query = query.outerjoin(model.StoredWorkflow.users_shared_with) query = query.outerjoin(model.StoredWorkflow.tags) - latest_workflow_load = joinedload("latest_workflow") + latest_workflow_load = joinedload(model.StoredWorkflow.latest_workflow) if not payload.skip_step_counts: latest_workflow_load = latest_workflow_load.undefer("step_count") - latest_workflow_load = latest_workflow_load.lazyload("steps") + latest_workflow_load = latest_workflow_load.lazyload(model.Workflow.steps) query = query.options(joinedload(model.StoredWorkflow.annotations)) query = query.options(latest_workflow_load) @@ -268,9 +268,11 @@ def get_stored_workflow(self, trans, workflow_id, by_stored_id=True) -> StoredWo ) ) stored_workflow = workflow_query.options( - joinedload("annotations"), - joinedload("tags"), - subqueryload("latest_workflow").joinedload("steps").joinedload("*"), + joinedload(trans.app.model.StoredWorkflow.annotations), + joinedload(trans.app.model.StoredWorkflow.tags), + subqueryload(trans.app.model.StoredWorkflow.latest_workflow) + .joinedload(trans.app.model.Workflow.steps) + .joinedload("*"), ).first() if stored_workflow is None: if not by_stored_id: @@ -366,10 +368,10 @@ def get_invocation(self, trans, decoded_invocation_id, eager=False) -> model.Wor if eager: q = q.options( subqueryload(model.WorkflowInvocation.steps) - .joinedload("implicit_collection_jobs") - .joinedload("jobs") - .joinedload("job") - .joinedload("input_datasets") + .joinedload(model.WorkflowInvocationStep.implicit_collection_jobs) + .joinedload(model.ImplicitCollectionJobs.jobs) + .joinedload(model.ImplicitCollectionJobsJobAssociation.job) + .joinedload(model.Job.input_datasets) ) workflow_invocation = q.get(decoded_invocation_id) if not workflow_invocation: From 7358b4421642e3c5749a13c6589dcbf2a1a6cb30 Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:20:25 -0500 Subject: [PATCH 10/16] Join/load: replace strings with attrs (managers.collections) --- lib/galaxy/managers/collections.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index 70370edd4526..1cd673b50c08 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -829,7 +829,9 @@ def _get_collection_contents_qry(self, parent_id, limit=None, offset=None): DCE = model.DatasetCollectionElement qry = Query(DCE).filter(DCE.dataset_collection_id == parent_id) qry = qry.order_by(DCE.element_index) - qry = qry.options(joinedload("child_collection"), joinedload("hda")) + qry = qry.options( + joinedload(model.DatasetCollectionElement.child_collection), joinedload(model.DatasetCollectionElement.hda) + ) if limit is not None: qry = qry.limit(int(limit)) if offset is not None: From 84c017c5d6c5cc186488baf3f89879d6d6f9cedd Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:22:13 -0500 Subject: [PATCH 11/16] Join/load: replace strings with attrs (webapps...controllers.page) --- lib/galaxy/webapps/galaxy/controllers/page.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/page.py b/lib/galaxy/webapps/galaxy/controllers/page.py index 180d782dea9d..b753e1a0786d 100644 --- a/lib/galaxy/webapps/galaxy/controllers/page.py +++ b/lib/galaxy/webapps/galaxy/controllers/page.py @@ -161,7 +161,11 @@ def build_initial_query(self, trans, **kwargs): trans.sa_session.query(self.model_class) .join("user") .filter(model.User.deleted == false()) - .options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating")) + .options( + joinedload(self.model_class.user).load_only("username"), + joinedload(self.model_class.annotations), + undefer("average_rating"), + ) ) def apply_query_filter(self, trans, query, **kwargs): From 69e91d339f7ae904aa30c13d80562402fb01cfc0 Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:24:01 -0500 Subject: [PATCH 12/16] Join/load: replace strings with attrs (webapps...controllers.visualization) --- lib/galaxy/webapps/galaxy/controllers/visualization.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/visualization.py b/lib/galaxy/webapps/galaxy/controllers/visualization.py index e56b249d8a68..248b777ef90c 100644 --- a/lib/galaxy/webapps/galaxy/controllers/visualization.py +++ b/lib/galaxy/webapps/galaxy/controllers/visualization.py @@ -287,8 +287,12 @@ def build_initial_query(self, trans, **kwargs): # See optimization description comments and TODO for tags in matching public histories query. return ( trans.sa_session.query(self.model_class) - .join("user") - .options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating")) + .join(self.model_class.user) + .options( + joinedload(self.model_class.user).load_only("username"), + joinedload(self.model_class.annotations), + undefer("average_rating"), + ) ) def apply_query_filter(self, trans, query, **kwargs): From fe7bf276583231098247914aed936433b276fa92 Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:36:08 -0500 Subject: [PATCH 13/16] Join/load: replace strings with attrs (toolshed-related) --- lib/tool_shed/webapp/api/repositories.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/tool_shed/webapp/api/repositories.py b/lib/tool_shed/webapp/api/repositories.py index 5dfc86d2ecf0..6ce3d482a355 100644 --- a/lib/tool_shed/webapp/api/repositories.py +++ b/lib/tool_shed/webapp/api/repositories.py @@ -38,6 +38,7 @@ BaseAPIController, HTTPBadRequest, ) +from tool_shed.webapp import model from tool_shed.dependencies import attribute_handlers from tool_shed.metadata import repository_metadata_manager from tool_shed.repository_types import util as rt_util @@ -118,7 +119,7 @@ def get_ordered_installable_revisions(self, trans, name=None, owner=None, **kwd) if owner is None: owner = kwd.get("owner", None) tsr_id = kwd.get("tsr_id", None) - eagerload_columns = ["downloadable_revisions"] + eagerload_columns = [model.Repository.downloadable_revisions] if None not in [name, owner]: # Get the repository information. repository = repository_util.get_repository_by_name_and_owner( @@ -217,7 +218,7 @@ def get_repository_revision_install_info(self, trans, name, owner, changeset_rev if name and owner and changeset_revision: # Get the repository information. repository = repository_util.get_repository_by_name_and_owner( - self.app, name, owner, eagerload_columns=["downloadable_revisions"] + self.app, name, owner, eagerload_columns=[model.Repository.downloadable_revisions] ) if repository is None: log.debug(f"Cannot locate repository {name} owned by {owner}") @@ -284,7 +285,7 @@ def get_installable_revisions(self, trans, **kwd): tsr_id = kwd.get("tsr_id", None) if tsr_id is not None: repository = repository_util.get_repository_in_tool_shed( - self.app, tsr_id, eagerload_columns=["downloadable_revisions"] + self.app, tsr_id, eagerload_columns=[model.Repository.downloadable_revisions] ) else: error_message = "Error in the Tool Shed repositories API in get_ordered_installable_revisions: " @@ -737,7 +738,7 @@ def updates(self, trans, **kwd): changeset_revision = kwd.get("changeset_revision", None) hexlify_this = util.asbool(kwd.get("hexlify", True)) repository = repository_util.get_repository_by_name_and_owner( - trans.app, name, owner, eagerload_columns=["downloadable_revisions"] + trans.app, name, owner, eagerload_columns=[model.Repository.downloadable_revisions] ) if repository and repository.downloadable_revisions: repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision( @@ -837,7 +838,7 @@ def metadata(self, trans, id, **kwd): downloadable_only = util.asbool(kwd.get("downloadable_only", "True")) all_metadata = {} repository = repository_util.get_repository_in_tool_shed( - self.app, id, eagerload_columns=["downloadable_revisions"] + self.app, id, eagerload_columns=[model.Repository.downloadable_revisions] ) for changeset, changehash in metadata_util.get_metadata_revisions( self.app, repository, sort_revisions=True, downloadable=downloadable_only From 1d6dfb585bd150ade2800ba0d187b8a33982847b Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:48:33 -0500 Subject: [PATCH 14/16] Join/load: replace strings with attrs (webapps...controllers.history) --- lib/galaxy/webapps/galaxy/controllers/history.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/history.py b/lib/galaxy/webapps/galaxy/controllers/history.py index 73d9717e7e0a..6411a3a158b6 100644 --- a/lib/galaxy/webapps/galaxy/controllers/history.py +++ b/lib/galaxy/webapps/galaxy/controllers/history.py @@ -208,7 +208,7 @@ def get_value(self, trans, grid, history): ] def build_initial_query(self, trans, **kwargs): - return trans.sa_session.query(self.model_class).join("users_shared_with") + return trans.sa_session.query(self.model_class).join(self.model_class.users_shared_with) def apply_query_filter(self, trans, query, **kwargs): return query.filter(model.HistoryUserShareAssociation.user == trans.user) From 4725e06d4e0fd551b64a1c7b0c7b5f425fdabca3 Mon Sep 17 00:00:00 2001 From: John Davis Date: Fri, 20 Jan 2023 18:49:54 -0500 Subject: [PATCH 15/16] Join/load: replace strings with attrs (managers.sharable) --- lib/galaxy/managers/sharable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/managers/sharable.py b/lib/galaxy/managers/sharable.py index aebef5bb039b..20eb3442f72d 100644 --- a/lib/galaxy/managers/sharable.py +++ b/lib/galaxy/managers/sharable.py @@ -222,7 +222,7 @@ def _query_shared_with(self, user, eagerloads=True, **kwargs): Return a query for this model already filtered to models shared with a particular user. """ - query = self.session().query(self.model_class).join("users_shared_with") + query = self.session().query(self.model_class).join(self.model_class.users_shared_with) if eagerloads is False: query = query.enable_eagerloads(False) # TODO: as filter in FilterParser also From 38afccd78022f81ecc0e075f7c6829c6d4dc09d3 Mon Sep 17 00:00:00 2001 From: John Davis Date: Sat, 21 Jan 2023 11:13:36 -0500 Subject: [PATCH 16/16] Fix linting --- lib/tool_shed/webapp/api/repositories.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tool_shed/webapp/api/repositories.py b/lib/tool_shed/webapp/api/repositories.py index 6ce3d482a355..86f6a9f859e0 100644 --- a/lib/tool_shed/webapp/api/repositories.py +++ b/lib/tool_shed/webapp/api/repositories.py @@ -38,7 +38,6 @@ BaseAPIController, HTTPBadRequest, ) -from tool_shed.webapp import model from tool_shed.dependencies import attribute_handlers from tool_shed.metadata import repository_metadata_manager from tool_shed.repository_types import util as rt_util @@ -51,6 +50,7 @@ repository_util, tool_util, ) +from tool_shed.webapp import model from tool_shed.webapp.search.repo_search import RepoSearch log = logging.getLogger(__name__)