simplify code

This commit is contained in:
bigcat88 2025-09-14 15:31:42 +03:00
parent 0b795dc7a7
commit a2ec1f7637
No known key found for this signature in database
GPG Key ID: 1F0BF0EC3CF22721
2 changed files with 10 additions and 23 deletions

View File

@ -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

View File

@ -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: