@@ -7,6 +7,7 @@ import { IDataStore, ILmdbDatabases, IQueryResult } from "../types"
77import { emitter , replaceReducer } from "../../redux"
88import { GatsbyIterable } from "../common/iterable"
99import { doRunQuery } from "./query/run-query"
10+ import _ from "lodash"
1011import {
1112 IRunFilterArg ,
1213 runFastFiltersAndSort ,
@@ -219,6 +220,8 @@ async function runQuery(args: IRunFilterArg): Promise<IQueryResult> {
219220
220221let lastOperationPromise : Promise < any > = Promise . resolve ( )
221222
223+ const debounceFunctionsPerNode = new Map ( )
224+
222225function updateDataStore ( action : ActionsUnion ) : void {
223226 switch ( action . type ) {
224227 case `DELETE_CACHE` : {
@@ -237,10 +240,26 @@ function updateDataStore(action: ActionsUnion): void {
237240 clearIndexes ( )
238241 break
239242 }
243+ case `ADD_CHILD_NODE_TO_PARENT_NODE` : {
244+ let fn
245+ const dbs = getDatabases ( )
246+ if ( ! debounceFunctionsPerNode . has ( action . payload . id ) ) {
247+ fn = _ . debounce ( _action => {
248+ updateNodes ( dbs . nodes , _action )
249+ updateNodesByType ( dbs . nodesByType , _action )
250+ } , 1000 )
251+ debounceFunctionsPerNode . set ( action . payload . id , fn )
252+ } else {
253+ fn = debounceFunctionsPerNode . get ( action . payload . id )
254+ }
255+
256+ // Call the debounce function.
257+ fn ( action )
258+ break
259+ }
240260 case `CREATE_NODE` :
241261 case `DELETE_NODE` :
242262 case `ADD_FIELD_TO_NODE` :
243- case `ADD_CHILD_NODE_TO_PARENT_NODE` :
244263 case `MATERIALIZE_PAGE_MODE` : {
245264 const dbs = getDatabases ( )
246265 const operationPromise = Promise . all ( [
0 commit comments