From b1c585daf455cfd9e97ca4b5fb4ec4491e6c3135 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Fri, 16 Oct 2026 17:29:00 +0800 Subject: [PATCH] =?UTF-8?q?W3-a=20=E7=BB=93=E6=9E=84=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E5=BD=B1=E5=93=8D=E9=9D=A2=EF=BC=9A=E4=B8=80=E6=89=B9?= =?UTF-8?q?=EF=BC=88=E4=B8=80=E6=AC=A1=E5=88=B7=E6=96=B0=EF=BC=89=E5=8F=AA?= =?UTF-8?q?=E8=AF=BB=E4=B8=80=E6=AC=A1=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 后台探查每批读完、刷新对象索引发现真删除的表时,各张表的影响面以前每张都重读一遍整个源的目录(structure_impact 不给 notes_by_table 时自己读)。一批几十张表、几千张表的库删了一批表时,这一读就重复几十次。改成一批(一次刷新)读一次、 各表共用;已发布模板的图本来就按任务缓存。行为不变,test_schema_changes、test_introspect_jobs、test_source_changes 照过。 --- backend/app/data/introspect_jobs.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/app/data/introspect_jobs.py b/backend/app/data/introspect_jobs.py index d1f0b993..0f730765 100644 --- a/backend/app/data/introspect_jobs.py +++ b/backend/app/data/introspect_jobs.py @@ -380,7 +380,7 @@ async def _record_index_changes(session: AsyncSession, row: Any, stats: so.Refre 真删除的表(table_removed,带影响面:目录里这张表的项、别的表指向它的关联关系、写死它的已发布模板)。出错只记日志。""" if not stats.removed_names and not (stats.added_names and not stats.first_build): return - from app.data import catalog_impact + from app.data import catalog, catalog_impact from app.data import schema_diff as sd from app.data import source_changes as sc @@ -399,13 +399,15 @@ async def _record_index_changes(session: AsyncSession, row: Any, stats: so.Refre SourceObject.name.in_(stats.removed_names)))).scalars()} tables_after = dict((row.schema_cache or {}).get("tables") or {}) specs = await catalog_impact.published_specs(session) + notes = {t: e.notes for t, e in (await catalog.read_catalog(session, row.id)).items()} for name in stats.removed_names: obj = gone.get(name) version = int(obj.struct_version or 0) if obj is not None else 0 meta = obj.meta if obj is not None and isinstance(obj.meta, dict) else None [(affects, severity)] = await catalog_impact.structure_impact( session, row, name, [sd.Diff(sd.TABLE_REMOVED)], before_meta=meta, - tables_after={k: v for k, v in tables_after.items() if k != name}, specs=specs) + tables_after={k: v for k, v in tables_after.items() if k != name}, specs=specs, + notes_by_table=notes) changes.append(sc.NewChange( kind=sd.TABLE_REMOVED, table=name, severity=severity, affects=affects, before={"kind": obj.kind if obj is not None else "table"}, struct_version_before=version or None, @@ -704,7 +706,7 @@ class _IntrospectRun(runtime.JobRun): got: so.Reflected, old: dict[str, Any], versions: dict[str, int]) -> None: """这一批的结构差异(不提交):读到的表指纹变了、又不是基线(schema_diff.is_baseline)的,逐条比出变化、算影响面; 以前读得到、这次读不到的记 table_reflect_failed。出错只记日志,不挡探查。""" - from app.data import catalog_impact + from app.data import catalog, catalog_impact from app.data import schema_diff as sd from app.data import source_changes as sc @@ -734,9 +736,12 @@ class _IntrospectRun(runtime.JobRun): if self._specs is None: self._specs = await catalog_impact.published_specs(session) tables_after = {**dict((row.schema_cache or {}).get("tables") or {}), **got.tables} + notes = ({t: e.notes for t, e in (await catalog.read_catalog(session, source_id)).items()} + if todo else {}) for seq, name, diffs, before in todo: impacts = await catalog_impact.structure_impact(session, row, name, diffs, before_meta=before, - tables_after=tables_after, specs=self._specs) + tables_after=tables_after, specs=self._specs, + notes_by_table=notes) after_v, before_v = versions.get(name), old[name].struct_version changes = [sc.NewChange(kind=d.kind, table=name, column=d.column, severity=severity, before=_side(d, "before"), after=_side(d, "after"), affects=affects,