From efdadb0def0dde178509d129b28dcafba6354f4b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Sat, 8 Aug 2026 21:02:58 +0000 Subject: [PATCH] =?UTF-8?q?=EC=84=B1=EB=8A=A5=20=EA=B0=9C=EC=84=A0:=20?= =?UTF-8?q?=EB=A7=A4=EB=B2=88=20=EC=8B=A4=ED=96=89=EB=90=98=EB=8A=94=20PRA?= =?UTF-8?q?GMA=20journal=5Fmode=3DWAL=EC=9D=84=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EC=8B=9C=201=EB=B2=88=20=EC=8B=A4=ED=96=89?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ CHANGELOG.md | 1 + job_store.py | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 341c7c91..700e653d 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,6 @@ +## 2024-08-08 - [JobStore SQLite 성능 최적화] +**Learning:** SQLite의 `PRAGMA journal_mode=WAL` 설정은 DB 파일 수준에서 영구적으로 유지되므로 매 연결마다 반복해서 실행할 필요가 없음. 매번 실행하면 매우 큰 오버헤드가 발생함. 여러 구문을 실행하기 위해 `conn.executescript()`를 활용. +**Action:** WAL 모드는 DB 초기화 시 스키마 생성과 함께 한 번만 실행되도록 변경. ## 2024-05-28 - Avoid O(N^2) Path.resolve() in Batch Processing **Learning:** Python's `pathlib.Path.resolve()` is relatively slow because it touches the filesystem to follow symlinks and resolve relative paths. When dealing with a batch operation (e.g., scanning large directories of media files), calculating protected files via `any(target == src.resolve() for src in sources)` on every check leads to massive O(N^2) CPU overhead. **Action:** Pre-resolve the entire list of candidate paths once into a `frozenset` at the beginning of the batch process. Pass this resolved set down the call stack so that collision/protection checks become O(1) hash map lookups instead of triggering millions of unnecessary disk access operations. diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cca1ced..984efc40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,3 +11,4 @@ ### Fixed - 단일·일괄 대상 크기 입력을 비웠을 때 이전 custom validity와 `aria-invalid` 상태를 즉시 초기화해 현재 필수 입력 상태를 정확히 전달합니다. +- SQLite JobStore 인스턴스 초기화 시 `PRAGMA journal_mode=WAL`을 한 번만 실행하도록 변경하여 DB 연결 성능을 크게 개선했습니다. diff --git a/job_store.py b/job_store.py index 15601581..cb06e8c7 100644 --- a/job_store.py +++ b/job_store.py @@ -95,7 +95,7 @@ def __init__(self, db_path: str) -> None: self._db_path = str(db_path) self._lock = threading.Lock() with self._connect() as conn: - conn.execute(_SCHEMA) + conn.executescript("PRAGMA journal_mode=WAL;\n" + _SCHEMA) @contextmanager def _connect(self) -> Iterator[sqlite3.Connection]: @@ -108,7 +108,6 @@ def _connect(self) -> Iterator[sqlite3.Connection]: conn = sqlite3.connect(self._db_path, timeout=30.0) try: conn.row_factory = sqlite3.Row - conn.execute("PRAGMA journal_mode=WAL") yield conn conn.commit() finally: