Skip to content

Commit

Permalink
fix: ReplicationStore schemaGC
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Dec 30, 2023
1 parent f00c23e commit f426e3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class SchemaService {
const prev = this.cache.get(id);
if (prev && result) {
this.cache.set(id, { ...prev, ...entityValue });

if (entityValue.value) {
prev.store.setInitialValue(entityValue.value);
}
}

return result;
Expand Down
17 changes: 17 additions & 0 deletions packages/erd-editor/src/engine/replication-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { actionsFilter } from '@/engine/rx-operators';
import { createStore } from '@/engine/store';
import { createHooks } from '@/engine/store-hooks';
import { Unsubscribe, ValuesType } from '@/internal-types';
import { procGC } from '@/services/schema-gc/procGC';
import { SchemaGCService } from '@/services/schema-gc/schemaGCService';
import { toSafeString } from '@/utils/validation';

type ReducerRecord = {
Expand Down Expand Up @@ -45,6 +47,7 @@ export function createReplicationStore(
store.subscribe(actions => subscriber.next(actions))
).pipe(actionsFilter(ChangeActionTypes), debounceTime(200));
const observers = new Set<Partial<ReducerRecord>>();
const schemaGCService = new SchemaGCService();

const on = (reducers: Partial<ReducerRecord>): Unsubscribe => {
observers.has(reducers) || observers.add(reducers);
Expand All @@ -69,6 +72,20 @@ export function createReplicationStore(
store.dispatchSync(
initialLoadJsonAction$(isEmpty(safeValue) ? '{}' : safeValue)
);
schemaGCService.run(toJson(store.state)).then(gcIds => {
const isChange =
gcIds.tableIds.length ||
gcIds.tableColumnIds.length ||
gcIds.relationshipIds.length ||
gcIds.indexIds.length ||
gcIds.indexColumnIds.length ||
gcIds.memoIds.length;

if (isChange) {
procGC(store.state, gcIds);
emit(InternalActionType.change, undefined);
}
});
};

const dispatchSync = (actions: Array<AnyAction> | AnyAction) => {
Expand Down

0 comments on commit f426e3f

Please sign in to comment.