mirror of
https://github.com/Comfy-Org/ComfyUI.git
synced 2026-08-24 18:10:27 +08:00
Let names and assertion messages carry what comments were carrying
Renames so the code states its own invariants: _SINGLETON_ROW_ID for the one-row version table, get_tag_origins_by_reference so the inner mapping's direction is in the name, _ROWS_PER_TRANSACTION for what the batch size bounds. In the tests, a named helper replaces the explanation of why the engine is shared across sessions, a named constant replaces the empty-string "any unique hash" sentinel, and each test's claim moves into its assertion message, where whoever's build just went red will actually read it.
This commit is contained in:
@@ -60,7 +60,7 @@ from app.assets.database.queries.semantics import (
|
||||
bulk_set_loader_paths,
|
||||
get_file_backed_references_page,
|
||||
get_semantics_version,
|
||||
get_tags_by_reference,
|
||||
get_tag_origins_by_reference,
|
||||
set_semantics_version,
|
||||
)
|
||||
from app.assets.database.queries.tags import (
|
||||
@@ -122,7 +122,7 @@ __all__ = [
|
||||
"get_references_by_paths_and_asset_ids",
|
||||
"get_references_for_prefixes",
|
||||
"get_semantics_version",
|
||||
"get_tags_by_reference",
|
||||
"get_tag_origins_by_reference",
|
||||
"get_unenriched_references",
|
||||
"get_unreferenced_unhashed_asset_ids",
|
||||
"insert_reference",
|
||||
|
||||
@@ -19,22 +19,22 @@ from app.assets.database.queries.common import (
|
||||
from app.assets.database.queries.tags import ensure_tags_exist
|
||||
from app.assets.helpers import get_utc_now
|
||||
|
||||
_VERSION_ROW_ID = 1
|
||||
_SINGLETON_ROW_ID = 1
|
||||
|
||||
AUTOMATIC_TAG_ORIGIN = "automatic"
|
||||
|
||||
|
||||
def get_semantics_version(session: Session) -> int:
|
||||
row = session.get(AssetSemanticsVersion, _VERSION_ROW_ID)
|
||||
row = session.get(AssetSemanticsVersion, _SINGLETON_ROW_ID)
|
||||
return int(row.version) if row is not None else 0
|
||||
|
||||
|
||||
def set_semantics_version(session: Session, version: int) -> None:
|
||||
row = session.get(AssetSemanticsVersion, _VERSION_ROW_ID)
|
||||
row = session.get(AssetSemanticsVersion, _SINGLETON_ROW_ID)
|
||||
if row is None:
|
||||
session.add(
|
||||
AssetSemanticsVersion(
|
||||
id=_VERSION_ROW_ID, version=int(version), updated_at=get_utc_now()
|
||||
id=_SINGLETON_ROW_ID, version=int(version), updated_at=get_utc_now()
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -93,7 +93,7 @@ def get_file_backed_references_page(
|
||||
]
|
||||
|
||||
|
||||
def get_tags_by_reference(
|
||||
def get_tag_origins_by_reference(
|
||||
session: Session, reference_ids: list[str]
|
||||
) -> dict[str, dict[str, str]]:
|
||||
if not reference_ids:
|
||||
|
||||
@@ -29,7 +29,7 @@ from app.assets.database.queries.semantics import (
|
||||
bulk_remove_automatic_tags,
|
||||
bulk_set_loader_paths,
|
||||
get_file_backed_references_page,
|
||||
get_tags_by_reference,
|
||||
get_tag_origins_by_reference,
|
||||
)
|
||||
from app.assets.helpers import normalize_tags
|
||||
from app.assets.semantics.step import InterruptCheck, SemanticsStepInterrupted
|
||||
@@ -41,7 +41,7 @@ from app.assets.services.path_utils import (
|
||||
)
|
||||
from app.database.db import create_session
|
||||
|
||||
_BATCH_SIZE = 500
|
||||
_ROWS_PER_TRANSACTION = 500
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -86,7 +86,7 @@ def reproject_derived_state(
|
||||
|
||||
with create_session() as session:
|
||||
rows = get_file_backed_references_page(
|
||||
session, after_id=after_id, limit=_BATCH_SIZE
|
||||
session, after_id=after_id, limit=_ROWS_PER_TRANSACTION
|
||||
)
|
||||
if not rows:
|
||||
return summary
|
||||
@@ -101,7 +101,9 @@ def _reproject_batch(
|
||||
vocabulary: set[str],
|
||||
summary: ReprojectionSummary,
|
||||
) -> None:
|
||||
stored_tags = get_tags_by_reference(session, [row.reference_id for row in rows])
|
||||
stored_tags = get_tag_origins_by_reference(
|
||||
session, [row.reference_id for row in rows]
|
||||
)
|
||||
|
||||
loader_paths: dict[str, str | None] = {}
|
||||
tags_to_add: list[tuple[str, str]] = []
|
||||
|
||||
Reference in New Issue
Block a user