fix(travel-proxy): db.py 중복 쿼리 제거 + 타입 힌트 개선
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional, Set
|
||||||
|
|
||||||
DB_PATH = os.getenv("TRAVEL_DB_PATH", "/data/thumbs/travel.db")
|
DB_PATH = os.getenv("TRAVEL_DB_PATH", "/data/thumbs/travel.db")
|
||||||
|
|
||||||
@@ -50,12 +50,7 @@ def get_photos_by_region(albums: List[str], page: int, size: int) -> Dict[str, A
|
|||||||
albums,
|
albums,
|
||||||
).fetchall()
|
).fetchall()
|
||||||
matched_albums = [{"album": r["album"], "count": r["cnt"]} for r in rows]
|
matched_albums = [{"album": r["album"], "count": r["cnt"]} for r in rows]
|
||||||
|
total = sum(r["cnt"] for r in rows)
|
||||||
total_row = conn.execute(
|
|
||||||
f"SELECT COUNT(*) as cnt FROM photos WHERE album IN ({placeholders})",
|
|
||||||
albums,
|
|
||||||
).fetchone()
|
|
||||||
total = total_row["cnt"]
|
|
||||||
|
|
||||||
offset = (page - 1) * size
|
offset = (page - 1) * size
|
||||||
items = conn.execute(
|
items = conn.execute(
|
||||||
@@ -142,7 +137,7 @@ def upsert_photo(album: str, filename: str, mtime: float) -> str:
|
|||||||
return "unchanged"
|
return "unchanged"
|
||||||
|
|
||||||
|
|
||||||
def remove_missing_photos(album: str, existing_filenames: set) -> int:
|
def remove_missing_photos(album: str, existing_filenames: Set[str]) -> int:
|
||||||
"""폴더에 없는 사진을 DB에서 제거. 제거 수 반환."""
|
"""폴더에 없는 사진을 DB에서 제거. 제거 수 반환."""
|
||||||
with _conn() as conn:
|
with _conn() as conn:
|
||||||
db_rows = conn.execute(
|
db_rows = conn.execute(
|
||||||
|
|||||||
Reference in New Issue
Block a user