fix(travel-proxy): indexer.py stat() 에러 핸들링 + updated 카운터 + 로깅 개선
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,9 +23,14 @@ def _scan_folder(folder: Path) -> List[Dict[str, Any]]:
|
|||||||
with os.scandir(folder) as entries:
|
with os.scandir(folder) as entries:
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if entry.is_file() and Path(entry.name).suffix.lower() in IMAGE_EXT:
|
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({
|
items.append({
|
||||||
"filename": entry.name,
|
"filename": entry.name,
|
||||||
"mtime": entry.stat().st_mtime,
|
"mtime": mtime,
|
||||||
})
|
})
|
||||||
return items
|
return items
|
||||||
|
|
||||||
@@ -73,8 +78,12 @@ def sync(
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
# 1. region_map.json에서 전체 앨범 폴더 수집
|
# 1. region_map.json에서 전체 앨범 폴더 수집
|
||||||
with open(region_map_path, "r", encoding="utf-8") as f:
|
try:
|
||||||
region_map = json.load(f)
|
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()
|
all_albums: Set[str] = set()
|
||||||
for v in region_map.values():
|
for v in region_map.values():
|
||||||
@@ -85,6 +94,7 @@ def sync(
|
|||||||
|
|
||||||
# 2. 각 앨범 폴더 스캔 → DB 동기화
|
# 2. 각 앨범 폴더 스캔 → DB 동기화
|
||||||
added = 0
|
added = 0
|
||||||
|
updated = 0
|
||||||
removed = 0
|
removed = 0
|
||||||
|
|
||||||
for album in sorted(all_albums):
|
for album in sorted(all_albums):
|
||||||
@@ -97,6 +107,8 @@ def sync(
|
|||||||
result = db.upsert_photo(album, item["filename"], item["mtime"])
|
result = db.upsert_photo(album, item["filename"], item["mtime"])
|
||||||
if result == "added":
|
if result == "added":
|
||||||
added += 1
|
added += 1
|
||||||
|
elif result == "updated":
|
||||||
|
updated += 1
|
||||||
|
|
||||||
removed += db.remove_missing_photos(album, existing_filenames)
|
removed += db.remove_missing_photos(album, existing_filenames)
|
||||||
|
|
||||||
@@ -113,12 +125,13 @@ def sync(
|
|||||||
|
|
||||||
duration = round(time.time() - start, 2)
|
duration = round(time.time() - start, 2)
|
||||||
logger.info(
|
logger.info(
|
||||||
"Sync complete: added=%d removed=%d thumbs=%d duration=%.2fs",
|
"Sync complete: added=%d updated=%d removed=%d thumbs=%d duration=%.2fs",
|
||||||
added, removed, thumbs_generated, duration,
|
added, updated, removed, thumbs_generated, duration,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"added": added,
|
"added": added,
|
||||||
|
"updated": updated,
|
||||||
"removed": removed,
|
"removed": removed,
|
||||||
"thumbs_generated": thumbs_generated,
|
"thumbs_generated": thumbs_generated,
|
||||||
"duration_sec": duration,
|
"duration_sec": duration,
|
||||||
|
|||||||
Reference in New Issue
Block a user