perf: Fix all 7 code analysis issues
HIGH (Performance):
- Replace 8 sync file operations with aiofiles in async context (storage, mail,
report_generator, dms_bridge, ai_assistant)
- Frontend bundle splitting: manualChunks for react-vendor, ui-components, tanstack,
markdown, icons, utils, i18n (ui chunk 936K → ~19K)
MEDIUM (Architecture):
- Worker circular deps: Replace direct plugin imports with job_registry.py pattern
(register_job/get_all_jobs, importlib-based lazy loading)
- App-wide ErrorBoundary: New ErrorBoundary.tsx component, wrapped in AppShell
and all standalone routes
LOW (Code Quality):
- N+1 query fix: selectinload(Contact.contact_persons) in list_contacts()
- O(n²) dedup fix: SQL GROUP BY for email/phone duplicates, Dict-based name grouping
- Response format standardization: 7 routes converted from plain arrays to
{items: [...], total: N} format
This commit is contained in:
@@ -884,7 +884,8 @@ async def list_threads(
|
||||
threads[tid] = {"thread_id": tid, "subject": mail.subject, "mail_count": 0, "mails": []}
|
||||
threads[tid]["mail_count"] += 1
|
||||
threads[tid]["mails"].append(mail_to_response(mail))
|
||||
return list(threads.values())
|
||||
items = list(threads.values())
|
||||
return {"items": items, "total": len(items)}
|
||||
|
||||
|
||||
# ─── Templates (F-MAIL-06) ───
|
||||
|
||||
@@ -1531,8 +1531,8 @@ async def send_mail_via_smtp(
|
||||
mime_type = att_info.get("mime_type", "application/octet-stream")
|
||||
if not file_path or not os.path.exists(file_path):
|
||||
continue
|
||||
with open(file_path, "rb") as f: # noqa: ASYNC230
|
||||
content = f.read()
|
||||
async with aiofiles.open(file_path, "rb") as f:
|
||||
content = await f.read()
|
||||
# Determine maintype/subtype from mime_type
|
||||
if "/" in mime_type:
|
||||
maintype, subtype = mime_type.split("/", 1)
|
||||
|
||||
Reference in New Issue
Block a user