Commit 8c44fce0 authored by cat-bro's avatar cat-bro
Browse files

pass app.toolbox from reindex_tool_function instead of using stored toolbox

parent f5c511be
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ class ConfiguresGalaxyMixin:

    def reindex_tool_search(self):
        # Call this when tools are added or removed.
        self.toolbox_search.build_index(tool_cache=self.tool_cache)
        self.toolbox_search.build_index(tool_cache=self.tool_cache, toolbox=self.toolbox)
        self.tool_cache.reset_status()

    def _set_enabled_container_types(self):
+7 −8
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ class ToolBoxSearch:
        for panel_view in toolbox.panel_views():
            panel_view_id = panel_view.id
            panel_index_dir = os.path.join(index_dir, panel_view_id)
            panel_searches[panel_view_id] = ToolPanelViewSearch(toolbox, panel_view_id, panel_index_dir, index_help=index_help)
            panel_searches[panel_view_id] = ToolPanelViewSearch(panel_view_id, panel_index_dir, index_help=index_help)
        self.panel_searches = panel_searches
        # We keep track of how many times the tool index has been rebuilt.
        # We start at -1, so that after the first index the count is at 0,
@@ -71,10 +71,10 @@ class ToolBoxSearch:
        # reindexing if the index count is equal to the toolbox reload count.
        self.index_count = -1

    def build_index(self, tool_cache, index_help: bool = True) -> None:
    def build_index(self, tool_cache, toolbox, index_help: bool = True) -> None:
        self.index_count += 1
        for panel_search in self.panel_searches.values():
            panel_search.build_index(tool_cache, index_help=index_help)
            panel_search.build_index(tool_cache, toolbox, index_help=index_help)

    def search(self, *args, **kwd) -> List[str]:
        panel_view = kwd.pop("panel_view")
@@ -90,7 +90,7 @@ class ToolPanelViewSearch:
    the Whoosh search library.
    """

    def __init__(self, toolbox, panel_view_id: str, index_dir: str, index_help: bool = True):
    def __init__(self, panel_view_id: str, index_dir: str, index_help: bool = True):
        self.schema = Schema(id=ID(stored=True, unique=True),
                             old_id=ID,
                             stub=KEYWORD,
@@ -101,14 +101,13 @@ class ToolPanelViewSearch:
                             labels=KEYWORD)
        self.rex = analysis.RegexTokenizer()
        self.index_dir = index_dir
        self.toolbox = toolbox
        self.panel_view_id = panel_view_id
        self.index = self._index_setup()

    def _index_setup(self) -> index.Index:
        return get_or_create_index(index_dir=self.index_dir, schema=self.schema)

    def build_index(self, tool_cache, index_help: bool = True) -> None:
    def build_index(self, tool_cache, toolbox, index_help: bool = True) -> None:
        """
        Prepare search index for tools loaded in toolbox.
        Use `tool_cache` to determine which tools need indexing and which tools should be expired.
@@ -132,8 +131,8 @@ class ToolPanelViewSearch:
            for tool_id in tool_ids_to_remove:
                writer.delete_by_term('id', tool_id)
            for tool_id in tool_cache._new_tool_ids - indexed_tool_ids:
                tool = self.toolbox.get_tool(tool_id)
                if tool and tool.is_latest_version and self.toolbox.panel_has_tool(tool, self.panel_view_id):
                tool = toolbox.get_tool(tool_id)
                if tool and tool.is_latest_version and toolbox.panel_has_tool(tool, self.panel_view_id):
                    if tool.hidden:
                        # we check if there is an older tool we can return
                        if tool.lineage: