mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-20 06:54:05 +00:00
optimization: initial scan speed(batching tags)
This commit is contained in:
@@ -6,6 +6,7 @@ from .projection import is_scalar, project_kv
|
||||
from .tags import (
|
||||
add_missing_tag_for_asset_id,
|
||||
ensure_tags_exist,
|
||||
insert_tags_from_batch,
|
||||
remove_missing_tag_for_asset_id,
|
||||
)
|
||||
|
||||
@@ -19,5 +20,6 @@ __all__ = [
|
||||
"ensure_tags_exist",
|
||||
"add_missing_tag_for_asset_id",
|
||||
"remove_missing_tag_for_asset_id",
|
||||
"insert_tags_from_batch",
|
||||
"visible_owner_clause",
|
||||
]
|
||||
|
||||
@@ -88,3 +88,19 @@ async def remove_missing_tag_for_asset_id(
|
||||
AssetInfoTag.tag_name == "missing",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def insert_tags_from_batch(session: AsyncSession, *, tag_rows: list[dict]) -> None:
|
||||
if session.bind.dialect.name == "sqlite":
|
||||
ins_links = (
|
||||
d_sqlite.insert(AssetInfoTag)
|
||||
.values(tag_rows)
|
||||
.on_conflict_do_nothing(index_elements=[AssetInfoTag.asset_info_id, AssetInfoTag.tag_name])
|
||||
)
|
||||
else:
|
||||
ins_links = (
|
||||
d_pg.insert(AssetInfoTag)
|
||||
.values(tag_rows)
|
||||
.on_conflict_do_nothing(index_elements=[AssetInfoTag.asset_info_id, AssetInfoTag.tag_name])
|
||||
)
|
||||
await session.execute(ins_links)
|
||||
|
||||
@@ -67,7 +67,7 @@ async def seed_from_path(
|
||||
info_name: str,
|
||||
tags: Sequence[str],
|
||||
owner_id: str = "",
|
||||
skip_tag_ensure: bool = False,
|
||||
collected_tag_rows: list[dict],
|
||||
) -> None:
|
||||
"""Creates Asset(hash=NULL), AssetCacheState(file_path), and AssetInfo exist for the path."""
|
||||
locator = os.path.abspath(abs_path)
|
||||
@@ -154,8 +154,6 @@ async def seed_from_path(
|
||||
if info_inserted:
|
||||
want = normalize_tags(tags)
|
||||
if want:
|
||||
if not skip_tag_ensure:
|
||||
await ensure_tags_exist(session, want, tag_type="user")
|
||||
tag_rows = [
|
||||
{
|
||||
"asset_info_id": new_info_id,
|
||||
@@ -165,19 +163,7 @@ async def seed_from_path(
|
||||
}
|
||||
for t in want
|
||||
]
|
||||
if dialect == "sqlite":
|
||||
ins_links = (
|
||||
d_sqlite.insert(AssetInfoTag)
|
||||
.values(tag_rows)
|
||||
.on_conflict_do_nothing(index_elements=[AssetInfoTag.asset_info_id, AssetInfoTag.tag_name])
|
||||
)
|
||||
else:
|
||||
ins_links = (
|
||||
d_pg.insert(AssetInfoTag)
|
||||
.values(tag_rows)
|
||||
.on_conflict_do_nothing(index_elements=[AssetInfoTag.asset_info_id, AssetInfoTag.tag_name])
|
||||
)
|
||||
await session.execute(ins_links)
|
||||
collected_tag_rows.extend(tag_rows)
|
||||
|
||||
if fname: # simple filename projection with single row
|
||||
meta_row = {
|
||||
|
||||
Reference in New Issue
Block a user