Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2026-07-06 - [Optimize SQLite WAL PRAGMA for short-lived connections]
**Learning:** SQLite's `PRAGMA journal_mode=WAL` is persistent per database file. In applications with many short-lived connections, executing it redundantly on every connection introduces unnecessary overhead.
**Action:** Execute `PRAGMA journal_mode=WAL` once during initialization (e.g., via `conn.executescript()` with the schema) rather than on every new 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.
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
### Fixed
- 단일·일괄 대상 크기 입력을 비웠을 때 이전 custom validity와 `aria-invalid` 상태를 즉시 초기화해 현재 필수 입력 상태를 정확히 전달합니다.
- 업로드 파일명의 경로 구분자를 정규화하여 POSIX에서도 Windows 형식의 클라이언트 경로가 일관된 basename으로 기록되도록 수정했습니다.

### 성능 개선
- `job_store.py` 및 `usage_metering.py`에서 매번 실행되던 `PRAGMA journal_mode=WAL` 구문을 데이터베이스 초기화 시에만 한 번 실행하도록 최적화하여 시스템 호출 및 쿼리 오버헤드를 줄였습니다.
3 changes: 1 addition & 2 deletions job_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(f"PRAGMA journal_mode=WAL;\n{_SCHEMA}")

@contextmanager
def _connect(self) -> Iterator[sqlite3.Connection]:
Expand All @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions usage_metering.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def __init__(self, db_path: str | Path) -> None:
self._db_path = path
self._lock = threading.Lock()
with closing(self._connect()) as conn:
with conn:
conn.execute(_SCHEMA)
conn.executescript(f"PRAGMA journal_mode=WAL;\n{_SCHEMA}")

def _connect(self) -> sqlite3.Connection:
"""Open a new short-lived connection with WAL mode enabled.
Expand All @@ -130,7 +129,6 @@ def _connect(self) -> sqlite3.Connection:
A fresh :class:`sqlite3.Connection` to the store's database.
"""
conn = sqlite3.connect(self._db_path, timeout=30.0)
conn.execute("PRAGMA journal_mode=WAL")
return conn

def record(
Expand Down
Loading