mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-18 22:20:03 +00:00
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>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""Shared utilities for database query modules."""
|
|
|
|
from typing import Iterable
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from app.assets.database.models import AssetReference
|
|
|
|
MAX_BIND_PARAMS = 800
|
|
|
|
|
|
def calculate_rows_per_statement(cols: int) -> int:
|
|
"""Calculate how many rows can fit in one statement given column count."""
|
|
return max(1, MAX_BIND_PARAMS // max(1, cols))
|
|
|
|
|
|
def iter_chunks(seq, n: int):
|
|
"""Yield successive n-sized chunks from seq."""
|
|
for i in range(0, len(seq), n):
|
|
yield seq[i : i + n]
|
|
|
|
|
|
def iter_row_chunks(rows: list[dict], cols_per_row: int) -> Iterable[list[dict]]:
|
|
"""Yield chunks of rows sized to fit within bind param limits."""
|
|
if not rows:
|
|
return
|
|
rows_per_stmt = calculate_rows_per_statement(cols_per_row)
|
|
for i in range(0, len(rows), rows_per_stmt):
|
|
yield rows[i : i + rows_per_stmt]
|
|
|
|
|
|
def build_visible_owner_clause(owner_id: str) -> sa.sql.ClauseElement:
|
|
"""Build owner visibility predicate for reads.
|
|
|
|
Owner-less rows are visible to everyone.
|
|
"""
|
|
owner_id = (owner_id or "").strip()
|
|
if owner_id == "":
|
|
return AssetReference.owner_id == ""
|
|
return AssetReference.owner_id.in_(["", owner_id])
|