fix(travel-proxy): indexer.py stat() 에러 핸들링 + updated 카운터 + 로깅 개선

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 09:05:12 +09:00
parent fac2e65ed8
commit e82ff83a5f

View File

@@ -23,9 +23,14 @@ def _scan_folder(folder: Path) -> List[Dict[str, Any]]:
with os.scandir(folder) as entries:
for entry in entries:
if entry.is_file() and Path(entry.name).suffix.lower() in IMAGE_EXT:
try:
mtime = entry.stat().st_mtime
except OSError as e:
logger.warning("Cannot stat %s: %s", entry.path, e)
continue
items.append({
"filename": entry.name,
"mtime": entry.stat().st_mtime,
"mtime": mtime,
})
return items
@@ -73,8 +78,12 @@ def sync(
start = time.time()
# 1. region_map.json에서 전체 앨범 폴더 수집
with open(region_map_path, "r", encoding="utf-8") as f:
region_map = json.load(f)
try:
with open(region_map_path, "r", encoding="utf-8") as f:
region_map = json.load(f)
except (FileNotFoundError, json.JSONDecodeError) as e:
logger.error("Failed to load region_map: %s", e)
raise
all_albums: Set[str] = set()
for v in region_map.values():
@@ -85,6 +94,7 @@ def sync(
# 2. 각 앨범 폴더 스캔 → DB 동기화
added = 0
updated = 0
removed = 0
for album in sorted(all_albums):
@@ -97,6 +107,8 @@ def sync(
result = db.upsert_photo(album, item["filename"], item["mtime"])
if result == "added":
added += 1
elif result == "updated":
updated += 1
removed += db.remove_missing_photos(album, existing_filenames)
@@ -113,12 +125,13 @@ def sync(
duration = round(time.time() - start, 2)
logger.info(
"Sync complete: added=%d removed=%d thumbs=%d duration=%.2fs",
added, removed, thumbs_generated, duration,
"Sync complete: added=%d updated=%d removed=%d thumbs=%d duration=%.2fs",
added, updated, removed, thumbs_generated, duration,
)
return {
"added": added,
"updated": updated,
"removed": removed,
"thumbs_generated": thumbs_generated,
"duration_sec": duration,