Skip to content

Commit

Permalink
Fix short ids in tool panel views.
Browse files Browse the repository at this point in the history
Use new data structure to optimize get_tool(exact=False) as well - should speed up certain kinds of toolbox related operations.
  • Loading branch information
jmchilton authored and mvdbeek committed Sep 10, 2023
1 parent cd50265 commit a45012b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/galaxy/tool_util/toolbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion test/integration/panel_views_1/custom_6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a45012b

Please sign in to comment.