mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
Implement cache
This commit is contained in:
parent
2eb44620b7
commit
637f1cf1b1
1 changed files with 32 additions and 15 deletions
|
|
@ -20,6 +20,8 @@ HEADERS = {
|
|||
PLUGIN_DIRECTORY = _env["python_directory_user"]
|
||||
PLUGIN_ENTRYPOINT = "Main"
|
||||
|
||||
_CACHE = {}
|
||||
|
||||
|
||||
def setup_config():
|
||||
is_config_updated = False
|
||||
|
|
@ -48,7 +50,7 @@ class Category:
|
|||
self.name = name
|
||||
self.base_download_url = base_download_url
|
||||
self.meta_url = meta_url
|
||||
self._plugins = None
|
||||
self._plugins = _CACHE.get("categories", {}).get(self.name)
|
||||
|
||||
async def get_plugins(self):
|
||||
if self._plugins is None:
|
||||
|
|
@ -60,10 +62,23 @@ class Category:
|
|||
plugins_info = json.loads(response.read())
|
||||
self._plugins = ([Plugin(plugin_info, self.base_download_url)
|
||||
for plugin_info in plugins_info.items()])
|
||||
self.set_category_plugins_global_cache(self._plugins)
|
||||
return self._plugins
|
||||
|
||||
def set_category_plugins_global_cache(self, plugins):
|
||||
if "categories" not in _CACHE:
|
||||
_CACHE["categories"] = {}
|
||||
_CACHE["categories"][self.name] = plugins
|
||||
|
||||
def unset_category_plugins_global_cache(self):
|
||||
try:
|
||||
del _CACHE["categories"][self.name]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
async def refresh(self):
|
||||
self._plugins = {}
|
||||
self.unset_category_plugins_global_cache()
|
||||
return await self.get_plugins()
|
||||
|
||||
|
||||
|
|
@ -349,33 +364,35 @@ class PluginWindow(popup.PopupWindow):
|
|||
class PluginManager:
|
||||
def __init__(self):
|
||||
self.request_headers = HEADERS
|
||||
self._index = {}
|
||||
|
||||
# @property
|
||||
# def index(self):
|
||||
# if not self._index:
|
||||
# loop = asyncio.get_event_loop()
|
||||
# self._index = loop.create_task(self.plugin_index())
|
||||
# return self._index
|
||||
|
||||
# def plugin_index(self):
|
||||
# loop = asyncio.get_event_loop()
|
||||
# loop.create_task(self.plugin_index())
|
||||
self._index = _CACHE.get("index", {})
|
||||
|
||||
async def get_index(self):
|
||||
global _INDEX
|
||||
if not self._index:
|
||||
request = urllib.request.Request(
|
||||
INDEX_META,
|
||||
headers=HEADERS
|
||||
)
|
||||
print(INDEX_META)
|
||||
response = await send_network_request(request)
|
||||
self._index = json.loads(response.read())
|
||||
self.set_index_global_cache(self._index)
|
||||
return self._index
|
||||
|
||||
async def refresh(self):
|
||||
self._index = {}
|
||||
self.unset_index_global_cache()
|
||||
return await self.get_index()
|
||||
|
||||
def set_index_global_cache(self, index):
|
||||
_CACHE["index"] = index
|
||||
|
||||
def unset_index_global_cache(self):
|
||||
try:
|
||||
del _CACHE["index"]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
async def soft_refresh(self):
|
||||
pass
|
||||
|
||||
|
|
@ -681,10 +698,10 @@ class PluginManagerWindow(ba.Window, PluginManager):
|
|||
color = (0, 1, 0)
|
||||
else:
|
||||
color = (1, 0.6, 0)
|
||||
else:
|
||||
color = (0.5, 0.5, 0.5)
|
||||
else:
|
||||
color = (1, 1, 1)
|
||||
else:
|
||||
color = (0.5, 0.5, 0.5)
|
||||
|
||||
plugin_to_update = self.plugins_in_current_view.get(plugin.name)
|
||||
if plugin_to_update:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue