mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-08 06:39:56 +00:00
fix: address code review feedback
- Fix missing import for compute_filename_for_reference in ingest.py - Apply code review fixes across routes, queries, scanner, seeder, hashing, ingest, path_utils, main, and server - Update and add tests for sync references and seeder Amp-Thread-ID: https://ampcode.com/threads/T-019cb61a-ed54-738c-a05f-9b5242e513f3 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -57,6 +57,7 @@ from app.assets.database.queries.tags import (
|
||||
remove_missing_tag_for_asset_id,
|
||||
remove_tags_from_reference,
|
||||
set_reference_tags,
|
||||
validate_tags_exist,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -114,4 +115,5 @@ __all__ = [
|
||||
"update_reference_updated_at",
|
||||
"upsert_asset",
|
||||
"upsert_reference",
|
||||
"validate_tags_exist",
|
||||
]
|
||||
|
||||
@@ -660,13 +660,16 @@ def restore_references_by_paths(session: Session, file_paths: list[str]) -> int:
|
||||
if not file_paths:
|
||||
return 0
|
||||
|
||||
result = session.execute(
|
||||
sa.update(AssetReference)
|
||||
.where(AssetReference.file_path.in_(file_paths))
|
||||
.where(AssetReference.is_missing == True) # noqa: E712
|
||||
.values(is_missing=False)
|
||||
)
|
||||
return result.rowcount
|
||||
total = 0
|
||||
for chunk in iter_chunks(file_paths, MAX_BIND_PARAMS):
|
||||
result = session.execute(
|
||||
sa.update(AssetReference)
|
||||
.where(AssetReference.file_path.in_(chunk))
|
||||
.where(AssetReference.is_missing == True) # noqa: E712
|
||||
.values(is_missing=False)
|
||||
)
|
||||
total += result.rowcount
|
||||
return total
|
||||
|
||||
|
||||
def get_unreferenced_unhashed_asset_ids(session: Session) -> list[str]:
|
||||
@@ -697,11 +700,14 @@ def delete_assets_by_ids(session: Session, asset_ids: list[str]) -> int:
|
||||
"""
|
||||
if not asset_ids:
|
||||
return 0
|
||||
session.execute(
|
||||
sa.delete(AssetReference).where(AssetReference.asset_id.in_(asset_ids))
|
||||
)
|
||||
result = session.execute(sa.delete(Asset).where(Asset.id.in_(asset_ids)))
|
||||
return result.rowcount
|
||||
total = 0
|
||||
for chunk in iter_chunks(asset_ids, MAX_BIND_PARAMS):
|
||||
session.execute(
|
||||
sa.delete(AssetReference).where(AssetReference.asset_id.in_(chunk))
|
||||
)
|
||||
result = session.execute(sa.delete(Asset).where(Asset.id.in_(chunk)))
|
||||
total += result.rowcount
|
||||
return total
|
||||
|
||||
|
||||
def get_references_for_prefixes(
|
||||
|
||||
@@ -37,6 +37,17 @@ class SetTagsDict(TypedDict):
|
||||
total: list[str]
|
||||
|
||||
|
||||
def validate_tags_exist(session: Session, tags: list[str]) -> None:
|
||||
"""Raise ValueError if any of the given tag names do not exist."""
|
||||
existing_tag_names = set(
|
||||
name
|
||||
for (name,) in session.execute(select(Tag.name).where(Tag.name.in_(tags))).all()
|
||||
)
|
||||
missing = [t for t in tags if t not in existing_tag_names]
|
||||
if missing:
|
||||
raise ValueError(f"Unknown tags: {missing}")
|
||||
|
||||
|
||||
def ensure_tags_exist(
|
||||
session: Session, names: Iterable[str], tag_type: str = "user"
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user