From e1c685ea5d72b509174461b2f03039cef3070dde Mon Sep 17 00:00:00 2001 From: dineug Date: Tue, 23 Apr 2024 19:39:09 +0900 Subject: [PATCH] fix: hook collection update --- .../src/engine/modules/relationship/hooks.ts | 14 +++++------ .../src/engine/modules/table-column/hooks.ts | 24 ++++++++++--------- .../src/utils/draw-relationship/sort.ts | 1 + 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/erd-editor/src/engine/modules/relationship/hooks.ts b/packages/erd-editor/src/engine/modules/relationship/hooks.ts index b5d18fdb..bbcbaf0a 100644 --- a/packages/erd-editor/src/engine/modules/relationship/hooks.ts +++ b/packages/erd-editor/src/engine/modules/relationship/hooks.ts @@ -42,7 +42,8 @@ const identificationHook: CO = function* (channel, state) { const collection = query(collections).collection('relationshipEntities'); const relationships = collection.selectByIds(doc.relationshipIds); - for (const { id, end, identification } of relationships) { + for (const relationship of relationships) { + const { end, identification } = relationship; const table = query(collections) .collection('tableEntities') .selectById(end.tableId); @@ -63,9 +64,7 @@ const identificationHook: CO = function* (channel, state) { continue; } - collection.updateOne(id, relationship => { - relationship.identification = value; - }); + relationship.identification = value; } }, 10, @@ -81,7 +80,8 @@ const startRelationshipHook: CO = function* (channel, state) { const collection = query(collections).collection('relationshipEntities'); const relationships = collection.selectByIds(doc.relationshipIds); - for (const { id, end, startRelationshipType } of relationships) { + for (const relationship of relationships) { + const { end, startRelationshipType } = relationship; const table = query(collections) .collection('tableEntities') .selectById(end.tableId); @@ -104,9 +104,7 @@ const startRelationshipHook: CO = function* (channel, state) { continue; } - collection.updateOne(id, relationship => { - relationship.startRelationshipType = value; - }); + relationship.startRelationshipType = value; } }, 10, diff --git a/packages/erd-editor/src/engine/modules/table-column/hooks.ts b/packages/erd-editor/src/engine/modules/table-column/hooks.ts index ee97fb7f..77aa4eb7 100644 --- a/packages/erd-editor/src/engine/modules/table-column/hooks.ts +++ b/packages/erd-editor/src/engine/modules/table-column/hooks.ts @@ -31,9 +31,7 @@ const changeColumnNotNullHook: CO = function* (channel, state) { const isNotNull = bHas(column.options, ColumnOption.notNull); if (isNotNull) return; - collection.updateOne(id, column => { - column.options = column.options | ColumnOption.notNull; - }); + column.options = column.options | ColumnOption.notNull; } ); }; @@ -50,11 +48,13 @@ const addColumnForeignKeyHook: CO = function* (channel, state) { } = state; if (!relationshipIds.includes(id)) return; - query(collections) + const columns = query(collections) .collection('tableColumnEntities') - .updateMany(end.columnIds, column => { - column.ui.keys = column.ui.keys | ColumnUIKey.foreignKey; - }); + .selectByIds(end.columnIds); + + for (const column of columns) { + column.ui.keys = column.ui.keys | ColumnUIKey.foreignKey; + } } ); }; @@ -76,11 +76,13 @@ const removeColumnForeignKeyHook: CO = function* (channel, state) { .selectById(id); if (!relationship) return; - query(collections) + const columns = query(collections) .collection('tableColumnEntities') - .updateMany(relationship.end.columnIds, column => { - column.ui.keys = column.ui.keys & ~ColumnUIKey.foreignKey; - }); + .selectByIds(relationship.end.columnIds); + + for (const column of columns) { + column.ui.keys = column.ui.keys & ~ColumnUIKey.foreignKey; + } } ); }; diff --git a/packages/erd-editor/src/utils/draw-relationship/sort.ts b/packages/erd-editor/src/utils/draw-relationship/sort.ts index 1c74496a..f3531e7f 100644 --- a/packages/erd-editor/src/utils/draw-relationship/sort.ts +++ b/packages/erd-editor/src/utils/draw-relationship/sort.ts @@ -34,6 +34,7 @@ const directionNameToDirection: Record = { [DirectionName.right]: Direction.right, }; +// TODO: concurrent export function relationshipSort(state: RootState) { const { doc: { tableIds, relationshipIds },