refactor: improve function naming for clarity and consistency

Rename functions to use clearer verb-based names:
- pick_best_live_path → select_best_live_path
- escape_like_prefix → escape_sql_like_string
- list_tree → list_files_recursively
- check_asset_file_fast → verify_asset_file_unchanged
- _seed_from_paths_batch → _batch_insert_assets_from_paths
- reconcile_cache_states_for_root → sync_cache_states_with_filesystem
- touch_asset_info_by_id → update_asset_info_access_time
- replace_asset_info_metadata_projection → set_asset_info_metadata
- expand_metadata_to_rows → convert_metadata_to_rows
- _rows_per_stmt → _calculate_rows_per_statement
- ensure_within_base → validate_path_within_base
- _cleanup_temp → _delete_temp_file_if_exists
- validate_hash_format → normalize_and_validate_hash
- get_relative_to_root_category_path_of_asset → get_asset_category_and_relative_path

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Luke Mino-Altherr
2026-02-03 14:20:36 -08:00
parent 481a2fa263
commit fef2f01671
15 changed files with 88 additions and 88 deletions

View File

@@ -24,7 +24,7 @@ from app.assets.api.schemas_in import (
HashMismatchError,
ParsedUpload,
)
from app.assets.api.upload import _cleanup_temp
from app.assets.api.upload import _delete_temp_file_if_exists
from app.assets.database.queries import (
asset_exists_by_hash,
fetch_asset_info_and_asset,
@@ -32,11 +32,11 @@ from app.assets.database.queries import (
get_asset_tags,
list_asset_infos_page,
list_cache_states_by_asset_id,
touch_asset_info_by_id,
update_asset_info_access_time,
)
from app.assets.helpers import pick_best_live_path
from app.assets.helpers import select_best_live_path
from app.assets.services.path_utils import (
ensure_within_base,
validate_path_within_base,
resolve_destination_from_tags,
)
from app.assets.services import (
@@ -168,11 +168,11 @@ def resolve_asset_content_for_download(
info, asset = pair
states = list_cache_states_by_asset_id(session, asset_id=asset.id)
abs_path = pick_best_live_path(states)
abs_path = select_best_live_path(states)
if not abs_path:
raise FileNotFoundError
touch_asset_info_by_id(session, asset_info_id=asset_info_id)
update_asset_info_access_time(session, asset_info_id=asset_info_id)
session.commit()
ctype = asset.mime_type or mimetypes.guess_type(info.name or abs_path)[0] or "application/octet-stream"
@@ -242,7 +242,7 @@ def upload_asset_from_temp_path(
ext = _ext if 0 < len(_ext) <= 16 else ""
hashed_basename = f"{digest}{ext}"
dest_abs = os.path.abspath(os.path.join(dest_dir, hashed_basename))
ensure_within_base(dest_abs, base_dir)
validate_path_within_base(dest_abs, base_dir)
content_type = (
mimetypes.guess_type(os.path.basename(src_for_ext), strict=False)[0]
@@ -325,13 +325,13 @@ def process_upload(
"hash": parsed.provided_hash,
})
except ValidationError as ve:
_cleanup_temp(parsed.tmp_path)
_delete_temp_file_if_exists(parsed.tmp_path)
raise AssetValidationError("INVALID_BODY", f"Validation failed: {ve.json()}")
# Validate models category against configured folders
if spec.tags and spec.tags[0] == "models":
if len(spec.tags) < 2 or spec.tags[1] not in folder_paths.folder_names_and_paths:
_cleanup_temp(parsed.tmp_path)
_delete_temp_file_if_exists(parsed.tmp_path)
category = spec.tags[1] if len(spec.tags) >= 2 else ""
raise AssetValidationError("INVALID_BODY", f"unknown models category '{category}'")
@@ -349,7 +349,7 @@ def process_upload(
raise AssetNotFoundError(f"Asset content {spec.hash} does not exist")
# Drain temp if we accidentally saved (e.g., hash field came after file)
_cleanup_temp(parsed.tmp_path)
_delete_temp_file_if_exists(parsed.tmp_path)
return result
# Otherwise, we must have a temp file path to ingest
@@ -365,13 +365,13 @@ def process_upload(
expected_asset_hash=spec.hash,
)
except ValueError as e:
_cleanup_temp(parsed.tmp_path)
_delete_temp_file_if_exists(parsed.tmp_path)
msg = str(e)
if "HASH_MISMATCH" in msg or msg.strip().upper() == "HASH_MISMATCH":
raise HashMismatchError("Uploaded file hash does not match provided hash.")
raise AssetValidationError("BAD_REQUEST", "Invalid inputs.")
except Exception:
_cleanup_temp(parsed.tmp_path)
_delete_temp_file_if_exists(parsed.tmp_path)
raise