mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-09 13:50:00 +08:00
性能优化 (#2126)
* 性能优化 * 代码改进 * 优化浏览器代际切换逻辑 * 统一缓存与生命周期 * 添加aiomysql依赖 * 优化插件路径处理逻辑,简化条件判断;在虚拟环境包管理器中添加编码和错误处理参数以增强稳定性 * 🚨 auto fix by pre-commit hooks * 优化Windows下的关闭逻辑 * 代码优化 * bugfix:修复配置重载问题 * bugfix:修复插件加载启动竞态问题 * 收敛事件入口和权限上下文 * 优化 Windows launcher 关闭重启兜底 --------- Co-authored-by: HibiKier <775757368@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
HibiKier
pre-commit-ci[bot]
parent
24c316cd2c
commit
5d92ccd3b0
@@ -51,8 +51,10 @@ class ManifestRegistry:
|
||||
self._manifest_cache: dict[str, TemplateManifest] = {}
|
||||
self._lock = asyncio.Lock()
|
||||
|
||||
def clear_cache(self):
|
||||
def clear_cache(self) -> int:
|
||||
size = len(self._manifest_cache)
|
||||
self._manifest_cache.clear()
|
||||
return size
|
||||
|
||||
async def get_manifest(
|
||||
self, component_path: str, skin: str | None = None
|
||||
@@ -362,6 +364,21 @@ class ThemeManager:
|
||||
tuple[type, str, str | None], ComponentDependency
|
||||
] = OrderedDict()
|
||||
|
||||
def clear_runtime_caches(self) -> dict[str, int]:
|
||||
cleared = {
|
||||
"asset_resolution": len(self._asset_resolution_cache),
|
||||
"global_template": len(self._global_template_cache),
|
||||
"component_dependency": len(self._component_dependency_cache),
|
||||
}
|
||||
self._asset_resolution_cache.clear()
|
||||
self._global_template_cache.clear()
|
||||
self._component_dependency_cache.clear()
|
||||
if self.manifest_registry:
|
||||
manifest_count = self.manifest_registry.clear_cache()
|
||||
if manifest_count:
|
||||
cleared["manifest"] = manifest_count
|
||||
return {key: value for key, value in cleared.items() if value}
|
||||
|
||||
@staticmethod
|
||||
def _get_lru_entry(cache: OrderedDict, key: Any) -> Any:
|
||||
value = cache.get(key)
|
||||
|
||||
Reference in New Issue
Block a user