diff --git a/app/database/services/content.py b/app/database/services/content.py index 8547a1bff..58fc6df04 100644 --- a/app/database/services/content.py +++ b/app/database/services/content.py @@ -1,3 +1,4 @@ +import contextlib import logging import os from datetime import datetime @@ -291,10 +292,8 @@ async def compute_hash_and_dedup_for_cache_state( state.asset_id = new_asset.id state.mtime_ns = mtime_ns state.needs_verify = False - try: + with contextlib.suppress(Exception): await remove_missing_tag_for_asset_id(session, asset_id=state.asset_id) - except Exception: - pass await session.flush() return state.asset_id @@ -311,15 +310,12 @@ async def compute_hash_and_dedup_for_cache_state( duplicate_asset_id=this_asset.id, canonical_asset_id=canonical.id, ) - # Refresh state after the merge state = await session.get(AssetCacheState, state_id) if state: state.mtime_ns = mtime_ns state.needs_verify = False - try: + with contextlib.suppress(Exception): await remove_missing_tag_for_asset_id(session, asset_id=canonical.id) - except Exception: - pass await session.flush() return canonical.id @@ -345,10 +341,8 @@ async def compute_hash_and_dedup_for_cache_state( if state: state.mtime_ns = mtime_ns state.needs_verify = False - try: + with contextlib.suppress(Exception): await remove_missing_tag_for_asset_id(session, asset_id=canonical.id) - except Exception: - pass await session.flush() return canonical.id # If we got here, the integrity error was not about hash uniqueness @@ -357,10 +351,8 @@ async def compute_hash_and_dedup_for_cache_state( # Claimed successfully state.mtime_ns = mtime_ns state.needs_verify = False - try: + with contextlib.suppress(Exception): await remove_missing_tag_for_asset_id(session, asset_id=this_asset.id) - except Exception: - pass await session.flush() return this_asset.id @@ -370,10 +362,8 @@ async def compute_hash_and_dedup_for_cache_state( this_asset.size_bytes = new_size state.mtime_ns = mtime_ns state.needs_verify = False - try: + with contextlib.suppress(Exception): await remove_missing_tag_for_asset_id(session, asset_id=this_asset.id) - except Exception: - pass await session.flush() return this_asset.id @@ -393,10 +383,8 @@ async def compute_hash_and_dedup_for_cache_state( state.asset_id = target_id state.mtime_ns = mtime_ns state.needs_verify = False - try: + with contextlib.suppress(Exception): await remove_missing_tag_for_asset_id(session, asset_id=target_id) - except Exception: - pass await session.flush() return target_id diff --git a/app/database/services/info.py b/app/database/services/info.py index 687431d59..a31818f0b 100644 --- a/app/database/services/info.py +++ b/app/database/services/info.py @@ -366,16 +366,15 @@ async def touch_asset_info_by_id( asset_info_id: str, ts: Optional[datetime] = None, only_if_newer: bool = True, -) -> int: +) -> bool: ts = ts or utcnow() stmt = sa.update(AssetInfo).where(AssetInfo.id == asset_info_id) if only_if_newer: stmt = stmt.where( sa.or_(AssetInfo.last_access_time.is_(None), AssetInfo.last_access_time < ts) ) - stmt = stmt.values(last_access_time=ts) - res = await session.execute(stmt) - return int(res.rowcount or 0) + stmt = stmt.values(last_access_time=ts).returning(AssetInfo.id) + return (await session.execute(stmt)).scalar_one_or_none() is not None async def delete_asset_info_by_id(session: AsyncSession, *, asset_info_id: str, owner_id: str) -> bool: