From a45012b33cc99ece6123d654cedff27f134c29da Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 7 Sep 2023 15:34:54 -0400 Subject: [PATCH] Fix short ids in tool panel views. Use new data structure to optimize get_tool(exact=False) as well - should speed up certain kinds of toolbox related operations. --- lib/galaxy/tool_util/toolbox/base.py | 13 +++++++++---- test/integration/panel_views_1/custom_6.yml | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/tool_util/toolbox/base.py b/lib/galaxy/tool_util/toolbox/base.py index 39fc18c68f01..c114e612ec76 100644 --- a/lib/galaxy/tool_util/toolbox/base.py +++ b/lib/galaxy/tool_util/toolbox/base.py @@ -95,7 +95,8 @@ def __init__(self, toolbox: "AbstractToolBox"): self.__toolbox = toolbox def has_tool(self, tool_id: str) -> bool: - return tool_id in self.__toolbox._tools_by_id + toolbox = self.__toolbox + return tool_id in toolbox._tools_by_id or tool_id in toolbox._tools_by_old_id def get_tool(self, tool_id: str): return self.__toolbox.get_tool(tool_id) @@ -153,6 +154,7 @@ def __init__( # so each will be present once in the above dictionary. The following # dictionary can instead hold multiple tools with different versions. self._tool_versions_by_id = {} + self._tools_by_old_id = {} self._workflows_by_id = {} # Cache for tool's to_dict calls specific to toolbox. Invalidates on toolbox reload. self._tool_to_dict_cache = {} @@ -710,9 +712,8 @@ def get_tool(self, tool_id, tool_version=None, get_all_versions=False, exact=Fal rval.append(lineage_tool) if not rval: # still no tool, do a deeper search and try to match by old ids - for tool in self._tools_by_id.values(): - if tool.old_id == tool_id: - rval.append(tool) + if tool_id in self._tools_by_old_id: + rval.extend(self._tools_by_old_id[tool_id]) if get_all_versions and tool_id in self._tool_versions_by_id: for tool in self._tool_versions_by_id[tool_id].values(): if tool not in rval: @@ -1152,6 +1153,10 @@ def register_tool(self, tool): self._tools_by_id[tool_id] = tool else: self._tools_by_id[tool_id] = tool + old_id = tool.old_id + if old_id not in self._tools_by_old_id: + self._tools_by_old_id[old_id] = [] + self._tools_by_old_id[old_id].append(tool) def package_tool(self, trans, tool_id): """ diff --git a/test/integration/panel_views_1/custom_6.yml b/test/integration/panel_views_1/custom_6.yml index 9567ba324135..b414f72254e5 100644 --- a/test/integration/panel_views_1/custom_6.yml +++ b/test/integration/panel_views_1/custom_6.yml @@ -2,7 +2,7 @@ name: Custom Panel in a New Section type: generic items: - type: section - name: My Completely New Sectin + name: My Completely New Section items: - type: label text: The Start