Skip to content

Commit

Permalink
Merge pull request #13776 from cat-bro/do-not-store-toolbox-on-ToolPa…
Browse files Browse the repository at this point in the history
…nelViewSearch
  • Loading branch information
nsoranzo authored Apr 21, 2022
2 parents 0da10b7 + 8c44fce commit e612a38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _configure_toolbox(self):

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):
Expand Down
15 changes: 7 additions & 8 deletions lib/galaxy/tools/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ def __init__(self, toolbox, index_dir: str, index_help: bool = True):
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,
# which is the same as the toolbox reload count. This way we can skip
# 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")
Expand All @@ -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,
Expand All @@ -101,14 +101,13 @@ def __init__(self, toolbox, panel_view_id: str, index_dir: str, index_help: bool
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.
Expand All @@ -132,8 +131,8 @@ def build_index(self, tool_cache, index_help: bool = True) -> None:
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:
Expand Down

0 comments on commit e612a38

Please sign in to comment.