From b8261db255759a4725fd30de280fae19ee1a375b Mon Sep 17 00:00:00 2001 From: abretaud Date: Fri, 24 Apr 2015 14:37:43 +0200 Subject: [PATCH 1/2] perf optimization: store tools' section in a dict instead of looping through the whole list of sections/tools for each tool --- lib/galaxy/tools/toolbox/base.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/galaxy/tools/toolbox/base.py b/lib/galaxy/tools/toolbox/base.py index 9656dd147ed..3b441704af8 100644 --- a/lib/galaxy/tools/toolbox/base.py +++ b/lib/galaxy/tools/toolbox/base.py @@ -53,6 +53,7 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): # shed_tool_conf.xml file. self._dynamic_tool_confs = [] self._tools_by_id = {} + self._integrated_section_by_tool = {} # Tool lineages can contain chains of related tools with different ids # so each will be present once in the above dictionary. The following # dictionary can instead hold multiple tools with different versions. @@ -217,19 +218,10 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): def get_integrated_section_for_tool( self, tool ): tool_id = tool.id - for key, item_type, item in self._integrated_tool_panel.panel_items_iter(): - if item: - if item_type == panel_item_types.TOOL: - if item.id == tool_id: - return '', '' - if item_type == panel_item_types.SECTION: - section_id = item.id or '' - section_name = item.name or '' - for section_key, section_item_type, section_item in item.panel_items_iter(): - if section_item_type == panel_item_types.TOOL: - if section_item: - if section_item.id == tool_id: - return section_id, section_name + + if tool_id in self._integrated_section_by_tool: + return self._integrated_section_by_tool[tool_id] + return None, None def __resolve_tool_path(self, tool_path, config_filename): @@ -310,6 +302,7 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): tool_id = key.replace( 'tool_', '', 1 ) if tool_id in self._tools_by_id: self.__add_tool_to_tool_panel( val, self._tool_panel, section=False ) + self._integrated_section_by_tool[tool_id] = '', '' elif item_type == panel_item_types.WORKFLOW: workflow_id = key.replace( 'workflow_', '', 1 ) if workflow_id in self._workflows_by_id: @@ -331,6 +324,7 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): tool_id = section_key.replace( 'tool_', '', 1 ) if tool_id in self._tools_by_id: self.__add_tool_to_tool_panel( section_val, section, section=True ) + self._integrated_section_by_tool[tool_id] = key, val.name elif section_item_type == panel_item_types.WORKFLOW: workflow_id = section_key.replace( 'workflow_', '', 1 ) if workflow_id in self._workflows_by_id: @@ -561,6 +555,9 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): if tool_key in itegrated_items: del itegrated_items[ tool_key ] + if tool_id in self._integrated_section_by_tool: + del self._integrated_section_by_tool[ tool_id ] + if section_key: _, tool_section = self.get_section( section_key ) if tool_section: @@ -934,6 +931,10 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): break if tool_id in self.data_manager_tools: del self.data_manager_tools[ tool_id ] + + if tool_id in self._integrated_section_by_tool: + del self._integrated_section_by_tool[ tool_id ] + # TODO: do we need to manually remove from the integrated panel here? message = "Removed the tool:
" message += "name: %s
" % tool.name From 911acd7a6ed364f2124e8673a02849f7922a0325 Mon Sep 17 00:00:00 2001 From: abretaud Date: Mon, 27 Apr 2015 11:44:30 +0200 Subject: [PATCH 2/2] handle adding/removing tools from toolshed --- lib/galaxy/tools/toolbox/base.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/galaxy/tools/toolbox/base.py b/lib/galaxy/tools/toolbox/base.py index 3b441704af8..1a04fdf4b74 100644 --- a/lib/galaxy/tools/toolbox/base.py +++ b/lib/galaxy/tools/toolbox/base.py @@ -546,18 +546,22 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): has_elems.insert( tool_panel_index, replacement_tool_key, replacement_tool_version ) + self._integrated_section_by_tool[ tool_id ] = available_tool_section_id, available_tool_section_name else: del has_elems[ tool_key ] + + if tool_id in self._integrated_section_by_tool: + del self._integrated_section_by_tool[ tool_id ] else: del has_elems[ tool_key ] + + if tool_id in self._integrated_section_by_tool: + del self._integrated_section_by_tool[ tool_id ] if remove_from_config: itegrated_items = integrated_has_elems.panel_items() if tool_key in itegrated_items: del itegrated_items[ tool_key ] - if tool_id in self._integrated_section_by_tool: - del self._integrated_section_by_tool[ tool_id ] - if section_key: _, tool_section = self.get_section( section_key ) if tool_section: @@ -678,6 +682,14 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): index=sub_index, internal=True, ) + + # Ensure each tool's section is stored + for section_key, section_item_type, section_item in integrated_elems.panel_items_iter(): + if section_item_type == panel_item_types.TOOL: + if section_item: + tool_id = section_key.replace( 'tool_', '', 1 ) + self._integrated_section_by_tool[tool_id] = integrated_section.id, integrated_section.name + if load_panel_dict: self._tool_panel[ key ] = section # Always load sections into the integrated_tool_panel. @@ -931,10 +943,6 @@ class AbstractToolBox( object, Dictifiable, ManagesIntegratedToolPanelMixin ): break if tool_id in self.data_manager_tools: del self.data_manager_tools[ tool_id ] - - if tool_id in self._integrated_section_by_tool: - del self._integrated_section_by_tool[ tool_id ] - # TODO: do we need to manually remove from the integrated panel here? message = "Removed the tool:
" message += "name: %s
" % tool.name