mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-26 01:19:06 +00:00
optimization: initial scan speed(batching metadata[filename])
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from .escape_like import escape_like_prefix
|
||||
from .fast_check import fast_asset_file_check
|
||||
from .filters import apply_metadata_filter, apply_tag_filters
|
||||
from .meta import insert_meta_from_batch
|
||||
from .ownership import visible_owner_clause
|
||||
from .projection import is_scalar, project_kv
|
||||
from .tags import (
|
||||
@@ -20,6 +21,7 @@ __all__ = [
|
||||
"ensure_tags_exist",
|
||||
"add_missing_tag_for_asset_id",
|
||||
"remove_missing_tag_for_asset_id",
|
||||
"insert_meta_from_batch",
|
||||
"insert_tags_from_batch",
|
||||
"visible_owner_clause",
|
||||
]
|
||||
|
||||
30
app/database/helpers/meta.py
Normal file
30
app/database/helpers/meta.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from sqlalchemy.dialects import postgresql as d_pg
|
||||
from sqlalchemy.dialects import sqlite as d_sqlite
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from ..models import AssetInfoMeta
|
||||
|
||||
|
||||
async def insert_meta_from_batch(session: AsyncSession, *, rows: list[dict]) -> None:
|
||||
"""Bulk insert rows into asset_info_meta with ON CONFLICT DO NOTHING.
|
||||
Each row should contain: asset_info_id, key, ordinal, val_str, val_num, val_bool, val_json
|
||||
"""
|
||||
if session.bind.dialect.name == "sqlite":
|
||||
ins = (
|
||||
d_sqlite.insert(AssetInfoMeta)
|
||||
.values(rows)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=[AssetInfoMeta.asset_info_id, AssetInfoMeta.key, AssetInfoMeta.ordinal]
|
||||
)
|
||||
)
|
||||
elif session.bind.dialect.name == "postgresql":
|
||||
ins = (
|
||||
d_pg.insert(AssetInfoMeta)
|
||||
.values(rows)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=[AssetInfoMeta.asset_info_id, AssetInfoMeta.key, AssetInfoMeta.ordinal]
|
||||
)
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError(f"Unsupported database dialect: {session.bind.dialect.name}")
|
||||
await session.execute(ins)
|
||||
@@ -97,10 +97,12 @@ async def insert_tags_from_batch(session: AsyncSession, *, tag_rows: list[dict])
|
||||
.values(tag_rows)
|
||||
.on_conflict_do_nothing(index_elements=[AssetInfoTag.asset_info_id, AssetInfoTag.tag_name])
|
||||
)
|
||||
else:
|
||||
elif session.bind.dialect.name == "postgresql":
|
||||
ins_links = (
|
||||
d_pg.insert(AssetInfoTag)
|
||||
.values(tag_rows)
|
||||
.on_conflict_do_nothing(index_elements=[AssetInfoTag.asset_info_id, AssetInfoTag.tag_name])
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError(f"Unsupported database dialect: {session.bind.dialect.name}")
|
||||
await session.execute(ins_links)
|
||||
|
||||
Reference in New Issue
Block a user