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 committed Oct 6, 2023
1 parent 098c9a5 commit 755d4f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 10 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 Expand Up @@ -1211,6 +1216,7 @@ def remove_tool_by_id(self, tool_id, remove_from_panel=True):
else:
tool = self._tools_by_id[tool_id]
del self._tools_by_id[tool_id]
self._tools_by_old_id[tool.old_id].remove(tool)
tool_cache = getattr(self.app, "tool_cache", None)
if tool_cache:
tool_cache.expire_tool(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
2 changes: 1 addition & 1 deletion test/integration/test_repository_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _uninstall_repository(self):
response = self.get_tool(assert_ok=False)
assert (
"err_msg" in response
), f"Expected an error message after tool install but response was {response.content}"
), f"Expected an error message after tool install but response was {response}"
assert response["err_msg"]
assert self.get_installed_repository_for(REPO.owner, REPO.name, REPO.changeset) is None

Expand Down

0 comments on commit 755d4f8

Please sign in to comment.