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
+10
View File
@@ -93,6 +93,16 @@ class ProjectDB:
).fetchall()
return [dict(r) for r in rows]
def list_projects_with_file_counts(self) -> list[dict]:
"""List projects with data file counts in a single query."""
rows = self.conn.execute(
"SELECT p.id, p.name, p.folder_path, p.description, p.created_at, p.updated_at, "
"COUNT(df.id) AS file_count "
"FROM projects p LEFT JOIN data_files df ON df.project_id = p.id "
"GROUP BY p.id ORDER BY p.name"
).fetchall()
return [dict(r) for r in rows]
def get_project(self, name: str) -> dict | None:
row = self.conn.execute(
"SELECT id, name, folder_path, description, created_at, updated_at "