Fix remaining blocking I/O calls and N+1 project query

- tab_batch_ng.py: async create_batch with to_thread save/sync
- tab_raw_ng.py: async do_save with to_thread, replace deepcopy
  with dict comprehension for display data
- main.py: async create_new with to_thread save
- tab_projects_ng.py: replace per-project count_data_files with
  single list_projects_with_file_counts JOIN query
- db.py: add list_projects_with_file_counts method

Zero blocking I/O calls remain in UI callbacks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-18 23:40:32 +01:00
parent 37e9e1001e
commit 589c84fd95
5 changed files with 26 additions and 18 deletions
+7 -8
View File
@@ -1,4 +1,4 @@
import copy
import asyncio
import json
from nicegui import ui
@@ -21,11 +21,10 @@ def render_raw_editor(state: AppState):
@ui.refreshable
def render_editor():
# Prepare display data
# Prepare display data — shallow copy, just pop keys
if hide_history.value:
display_data = copy.deepcopy(data)
display_data.pop(KEY_HISTORY_TREE, None)
display_data.pop(KEY_PROMPT_HISTORY, None)
display_data = {k: v for k, v in data.items()
if k not in (KEY_HISTORY_TREE, KEY_PROMPT_HISTORY)}
else:
display_data = data
@@ -40,7 +39,7 @@ def render_raw_editor(state: AppState):
value=json_str,
).classes('w-full font-mono').props('outlined rows=30')
def do_save():
async def do_save():
try:
input_data = json.loads(text_area.value)
@@ -51,9 +50,9 @@ def render_raw_editor(state: AppState):
if KEY_PROMPT_HISTORY in data:
input_data[KEY_PROMPT_HISTORY] = data[KEY_PROMPT_HISTORY]
save_json(file_path, input_data)
await asyncio.to_thread(save_json, file_path, input_data)
if state.db_enabled and state.current_project and state.db:
sync_to_db(state.db, state.current_project, file_path, input_data)
await asyncio.to_thread(sync_to_db, state.db, state.current_project, file_path, input_data)
data.clear()
data.update(input_data)