perf(travel-proxy): 배치 DB 연결 + nginx sync timeout 600s
- db.py: batch_sync_album, batch_mark_thumbs_done 추가 - indexer.py: 앨범 단위 배치 동기화로 전환 - nginx: /api/travel/ proxy_read_timeout 600s 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -175,3 +175,59 @@ def mark_thumb_done(album: str, filename: str) -> None:
|
||||
"UPDATE photos SET has_thumb = 1 WHERE album = ? AND filename = ?",
|
||||
(album, filename),
|
||||
)
|
||||
|
||||
|
||||
def batch_sync_album(album: str, items: List[Dict[str, Any]], existing_filenames: Set[str]) -> Dict[str, int]:
|
||||
"""앨범 단위 배치 동기화. 단일 커넥션으로 upsert + 삭제 처리."""
|
||||
added = updated = 0
|
||||
with _conn() as conn:
|
||||
for item in items:
|
||||
existing = conn.execute(
|
||||
"SELECT mtime FROM photos WHERE album = ? AND filename = ?",
|
||||
(album, item["filename"]),
|
||||
).fetchone()
|
||||
if not existing:
|
||||
conn.execute(
|
||||
"INSERT INTO photos (album, filename, mtime, has_thumb) VALUES (?, ?, ?, 0)",
|
||||
(album, item["filename"], item["mtime"]),
|
||||
)
|
||||
added += 1
|
||||
elif existing["mtime"] != item["mtime"]:
|
||||
conn.execute(
|
||||
"UPDATE photos SET mtime = ?, has_thumb = 0 WHERE album = ? AND filename = ?",
|
||||
(item["mtime"], album, item["filename"]),
|
||||
)
|
||||
updated += 1
|
||||
|
||||
# 삭제 처리
|
||||
db_rows = conn.execute(
|
||||
"SELECT filename FROM photos WHERE album = ?", (album,)
|
||||
).fetchall()
|
||||
db_filenames = {r["filename"] for r in db_rows}
|
||||
to_remove = db_filenames - existing_filenames
|
||||
|
||||
removed = len(to_remove)
|
||||
if to_remove:
|
||||
placeholders = ",".join("?" for _ in to_remove)
|
||||
conn.execute(
|
||||
f"DELETE FROM photos WHERE album = ? AND filename IN ({placeholders})",
|
||||
[album, *to_remove],
|
||||
)
|
||||
conn.execute(
|
||||
f"DELETE FROM album_covers WHERE album = ? AND filename IN ({placeholders})",
|
||||
[album, *to_remove],
|
||||
)
|
||||
|
||||
return {"added": added, "updated": updated, "removed": removed}
|
||||
|
||||
|
||||
def batch_mark_thumbs_done(items: List[Dict[str, str]]) -> None:
|
||||
"""썸네일 생성 완료 배치 표시."""
|
||||
if not items:
|
||||
return
|
||||
with _conn() as conn:
|
||||
for item in items:
|
||||
conn.execute(
|
||||
"UPDATE photos SET has_thumb = 1 WHERE album = ? AND filename = ?",
|
||||
(item["album"], item["filename"]),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user