From 457ce5de209e6099858ad726357ac83ba432679c Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Mon, 10 Aug 2026 20:49:52 +0000 Subject: [PATCH] =?UTF-8?q?job=5Fstore.py=EC=97=90=EC=84=9C=20=EB=A7=A4=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=EB=A7=88=EB=8B=A4=20=EC=8B=A4=ED=96=89?= =?UTF-8?q?=EB=90=98=EB=8D=98=20PRAGMA=20journal=5Fmode=3DWAL=20=EA=B5=AC?= =?UTF-8?q?=EB=AC=B8=EC=9D=84=20=EC=8A=A4=ED=82=A4=EB=A7=88=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EC=8B=9C=20=EB=8B=A8=20=ED=95=9C=20?= =?UTF-8?q?=EB=B2=88=EB=A7=8C=20=EC=8B=A4=ED=96=89=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD=ED=95=98=EC=97=AC=20=EC=84=B1?= =?UTF-8?q?=EB=8A=A5=20=ED=96=A5=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 4 ++++ CHANGELOG.md | 2 ++ job_store.py | 9 ++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 341c7c91..56ea8d0f 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,7 @@ +## 2026-08-10 - [Persistent SQLite WAL Mode] +**Learning:** SQLite's WAL journal mode (PRAGMA journal_mode=WAL) is persistent per database file. In applications creating many short-lived connections, executing it on every connection introduces unnecessary overhead. +**Action:** Execute persistent PRAGMAs like journal_mode=WAL once during schema initialization (e.g., using conn.executescript) rather than repeatedly on every connection. + ## 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..b9fadb11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,3 +11,5 @@ ### Fixed - 단일·일괄 대상 크기 입력을 비웠을 때 이전 custom validity와 `aria-invalid` 상태를 즉시 초기화해 현재 필수 입력 상태를 정확히 전달합니다. + +- `job_store.py`에서 매 연결마다 실행되던 SQLite `PRAGMA journal_mode=WAL` 구문을 스키마 초기화 시 한 번만 실행하도록 최적화하여 불필요한 오버헤드 감소 diff --git a/job_store.py b/job_store.py index 15601581..7222f45f 100644 --- a/job_store.py +++ b/job_store.py @@ -95,20 +95,19 @@ 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]: - """Open a new WAL-mode connection to the underlying database. + """Open a new connection to the underlying database. Yields: - A short-lived ``sqlite3.Connection`` with WAL journaling and - a row factory that yields ``sqlite3.Row`` objects. + A short-lived ``sqlite3.Connection`` and a row factory that yields + ``sqlite3.Row`` objects. """ 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: