mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #3729 from mvdbeek/cleanup_tool_cache
Remove outdated items from tool cache when reloading the toolbox
This commit is contained in:
@@ -86,6 +86,7 @@ def reload_tool(app, **kwargs):
|
||||
def reload_toolbox(app, **kwargs):
|
||||
log.debug("Executing toolbox reload on '%s'", app.config.server_name)
|
||||
reload_count = app.toolbox._reload_count
|
||||
app.tool_cache.cleanup()
|
||||
app.toolbox = _get_new_toolbox(app)
|
||||
app.toolbox._reload_count = reload_count + 1
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import os
|
||||
|
||||
from galaxy.util.hash_util import md5_hash_file
|
||||
|
||||
|
||||
class ToolCache(object):
|
||||
@@ -7,9 +10,20 @@ class ToolCache(object):
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._hash_by_tool_paths = {}
|
||||
self._tools_by_path = {}
|
||||
self._tool_paths_by_id = {}
|
||||
|
||||
def cleanup(self):
|
||||
"""Remove uninstalled tools from tool cache if they are not on disk anymore or if their content has changed."""
|
||||
paths_to_cleanup = {path: tool.all_ids for path, tool in self._tools_by_path.items() if not os.path.exists(path) or md5_hash_file(path) != self._hash_by_tool_paths[path]}
|
||||
for config_filename, tool_ids in paths_to_cleanup.items():
|
||||
del self._hash_by_tool_paths[config_filename]
|
||||
del self._tools_by_path[config_filename]
|
||||
for tool_id in tool_ids:
|
||||
if tool_id in self._tool_paths_by_id:
|
||||
del self._tool_paths_by_id[tool_id]
|
||||
|
||||
def get_tool(self, config_filename):
|
||||
""" Get the tool from the cache if the tool is up to date.
|
||||
"""
|
||||
@@ -18,10 +32,13 @@ class ToolCache(object):
|
||||
def expire_tool(self, tool_id):
|
||||
if tool_id in self._tool_paths_by_id:
|
||||
config_filename = self._tool_paths_by_id[tool_id]
|
||||
del self._hash_by_tool_paths[config_filename]
|
||||
del self._tool_paths_by_id[tool_id]
|
||||
del self._tools_by_path[config_filename]
|
||||
|
||||
def cache_tool(self, config_filename, tool):
|
||||
tool_hash = md5_hash_file(config_filename)
|
||||
tool_id = str( tool.id )
|
||||
self._hash_by_tool_paths[config_filename] = tool_hash
|
||||
self._tool_paths_by_id[tool_id] = config_filename
|
||||
self._tools_by_path[config_filename] = tool
|
||||
|
||||
Reference in New Issue
Block a user