Luke Mino-Altherr
8ff4d38ad1
refactor(assets): merge AssetInfo and AssetCacheState into AssetReference
...
This change solves the basename collision bug by using UNIQUE(file_path) on the
unified asset_references table. Key changes:
Database:
- Migration 0005 merges asset_cache_states and asset_infos into asset_references
- AssetReference now contains: cache state fields (file_path, mtime_ns, needs_verify,
is_missing, enrichment_level) plus info fields (name, owner_id, preview_id, etc.)
- AssetReferenceMeta replaces AssetInfoMeta
- AssetReferenceTag replaces AssetInfoTag
- UNIQUE constraint on file_path prevents duplicate entries for same file
Code:
- New unified query module: asset_reference.py (replaces asset_info.py, cache_state.py)
- Updated scanner, seeder, and services to use AssetReference
- Updated API routes to use reference_id instead of asset_info_id
Tests:
- All 175 unit tests updated and passing
- Integration tests require server environment (not run here)
Amp-Thread-ID: https://ampcode.com/threads/T-019c4fe8-9dcb-75ce-bea8-ea786343a581
Co-authored-by: Amp <amp@ampcode.com >
2026-02-11 20:03:10 -08:00
Luke Mino-Altherr
8c4eb9a659
refactor(assets): consolidate duplicated query utilities and remove unused code
...
- Extract shared helpers to database/queries/common.py:
- MAX_BIND_PARAMS, calculate_rows_per_statement, iter_chunks, iter_row_chunks
- build_visible_owner_clause
- Remove duplicate _compute_filename_for_asset, consolidate in path_utils.py
- Remove unused get_asset_info_with_tags (duplicated get_asset_detail)
- Remove redundant __all__ from cache_state.py
- Make internal helpers private (_check_is_scalar)
Amp-Thread-ID: https://ampcode.com/threads/T-019c2ad9-9432-7451-94a8-79287dbbb19e
Co-authored-by: Amp <amp@ampcode.com >
2026-02-11 17:41:38 -08:00
Luke Mino-Altherr
fe59234476
chore: sort imports in assets package
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-02-11 17:41:38 -08:00
Luke Mino-Altherr
915d21afcb
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 >
2026-02-11 17:41:37 -08:00
Luke Mino-Altherr
1f9272bc94
refactor: rename functions to verb-based naming convention
...
Rename functions across app/assets/ to follow verb-based naming:
- is_scalar → check_is_scalar
- project_kv → expand_metadata_to_rows
- _visible_owner_clause → _build_visible_owner_clause
- _chunk_rows → _iter_row_chunks
- _at_least_one → _validate_at_least_one_field
- _tags_norm → _normalize_tags_field
- _ser_dt → _serialize_datetime
- _ser_updated → _serialize_updated_at
- _error_response → _build_error_response
- _validation_error_response → _build_validation_error_response
- file_sender → stream_file_chunks
- seed_assets_endpoint → seed_assets
- utcnow → get_utc_now
- _safe_sort_field → _validate_sort_field
- _safe_filename → _sanitize_filename
- fast_asset_file_check → check_asset_file_fast
- prefixes_for_root → get_prefixes_for_root
- blake3_hash → compute_blake3_hash
- blake3_hash_async → compute_blake3_hash_async
- _is_within → _check_is_within
- _rel → _compute_relative
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com >
2026-02-11 17:41:37 -08:00
Luke Mino-Altherr
e8edc4aa93
Move get_comfy_models_folders to path_utils.py to avoid late import
...
Amp-Thread-ID: https://ampcode.com/threads/T-019c2510-33fa-7199-ae4b-bc31102277a7
Co-authored-by: Amp <amp@ampcode.com >
2026-02-11 17:41:37 -08:00
Luke Mino-Altherr
24ca007bf6
Refactor helpers.py: move functions to their respective modules
...
- Move scanner-only functions to scanner.py
- Move query-only functions (is_scalar, project_kv) to asset_info.py
- Move get_query_dict to routes.py
- Create path_utils.py service for path-related functions
- Reduce helpers.py to shared utilities only
Amp-Thread-ID: https://ampcode.com/threads/T-019c2510-33fa-7199-ae4b-bc31102277a7
Co-authored-by: Amp <amp@ampcode.com >
2026-02-11 17:41:37 -08:00