Skip to content

Commit 5aae033

Browse files
author
lxfight
committed
perf(plugin): use asyncio.gather for concurrent page discovery
Replace sequential await loop with concurrent processing to avoid blocking on disk I/O when discovering plugin pages.
1 parent ec4028d commit 5aae033

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

astrbot/dashboard/routes/plugin.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,23 @@ def _get_plugin_installed_at(self, plugin) -> str | None:
12621262
async def get_plugins(self):
12631263
_plugin_resp = []
12641264
plugin_name = request.args.get("name")
1265-
for plugin in self.plugin_manager.context.get_all_stars():
1266-
if plugin_name and plugin.name != plugin_name:
1267-
continue
1265+
1266+
plugins = [
1267+
p
1268+
for p in self.plugin_manager.context.get_all_stars()
1269+
if not (plugin_name and p.name != plugin_name)
1270+
]
1271+
1272+
async def process_plugin(plugin):
12681273
logo_url = None
12691274
if plugin.logo_path:
12701275
logo_url = await self.get_plugin_logo_token(plugin.logo_path)
12711276
pages = await self._discover_plugin_pages(plugin)
1277+
return plugin, logo_url, pages
1278+
1279+
results = await asyncio.gather(*(process_plugin(p) for p in plugins))
1280+
1281+
for plugin, logo_url, pages in results:
12721282
_t = {
12731283
"name": plugin.name,
12741284
"repo": "" if plugin.repo is None else plugin.repo,
@@ -1298,6 +1308,7 @@ async def get_plugins(self):
12981308
):
12991309
continue
13001310
_plugin_resp.append(_t)
1311+
_plugin_resp.append(_t)
13011312
return (
13021313
Response()
13031314
.ok(_plugin_resp, message=self.plugin_manager.failed_plugin_info)

0 commit comments

Comments
 (0)