perf(import): 优化账号导入弹窗为秒开体验并支持批量回查校验

This commit is contained in:
liumangmang
2026-07-01 10:00:40 +08:00
parent 88c783b922
commit efd0a88249
3 changed files with 103 additions and 46 deletions
+26 -11
View File
@@ -36,7 +36,7 @@ from app.schemas.website import (
WebsiteBatchSyncResponse,
)
from app.services.website_client import Sub2ApiWebsiteClient
from app.services.website_client import Sub2ApiWebsiteClient, _extract_id
from app.services.website_sync import (
binding_sources,
sync_binding,
@@ -428,13 +428,35 @@ def sync_imported_upstream_keys(
)
items: list[ImportAccountItem] = []
with _client(website) as c:
remote_accounts = None
try:
remote_accounts = c.list_accounts()
except Exception as e:
logger.warning("failed to list accounts for website %s at sync: %s", wid, e)
if remote_accounts is not None:
remote_ids = set()
for acc in remote_accounts:
acc_id = _extract_id(acc)
if acc_id:
remote_ids.add(str(acc_id))
else:
remote_ids = None
for row in rows:
platform = _detect_platform(f"{row.group_name} {row.group_id} {row.key_name}", "openai")
if not row.imported_account_id:
continue
old_account_id = row.imported_account_id
exists = c.account_exists(row.imported_account_id)
if exists is False:
if remote_ids is None:
items.append(ImportAccountItem(
upstream_key_id=row.id, source_group_id=row.group_id,
source_group_name=row.group_name, account_id=old_account_id,
platform=platform, status="check_failed",
message="无法校验目标账号存在性(拉取账号列表失败)",
))
elif str(old_account_id) not in remote_ids:
row.imported_website_id = None
row.imported_account_id = None
row.imported_at = None
@@ -445,18 +467,11 @@ def sync_imported_upstream_keys(
platform=platform, status="stale_cleared",
message="目标账号已删除,已清除导入标记",
))
elif exists is True:
items.append(ImportAccountItem(
upstream_key_id=row.id, source_group_id=row.group_id,
source_group_name=row.group_name, account_id=old_account_id,
platform=platform, status="exists", message="目标账号仍存在",
))
else:
items.append(ImportAccountItem(
upstream_key_id=row.id, source_group_id=row.group_id,
source_group_name=row.group_name, account_id=old_account_id,
platform=platform, status="check_failed",
message="无法校验目标账号存在性(目标网站认证/网络问题)",
platform=platform, status="exists", message="目标账号仍存在",
))
db.commit()
cleared_count = len([i for i in items if i.status == "stale_cleared"])