Skip to content

Commit 23b2620

Browse files
committed
fix race
1 parent 02321d9 commit 23b2620

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/gatsby/src/datastore/lmdb/lmdb-datastore.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ function updateDataStore(action: ActionsUnion): void {
202202
case `ADD_CHILD_NODE_TO_PARENT_NODE`:
203203
case `MATERIALIZE_PAGE_MODE`: {
204204
const dbs = getDatabases()
205-
lastOperationPromise = Promise.all([
205+
const operationPromise = Promise.all([
206206
updateNodes(dbs.nodes, action),
207207
updateNodesByType(dbs.nodesByType, action),
208208
])
209+
lastOperationPromise = operationPromise
209210

210211
// if create is used in the same transaction as delete we should remove it from cache
211212
if (action.type === `CREATE_NODE`) {
@@ -216,8 +217,11 @@ function updateDataStore(action: ActionsUnion): void {
216217
preSyncDeletedNodeIdsCache.add(
217218
((action as IDeleteNodeAction).payload as IGatsbyNode).id
218219
)
219-
lastOperationPromise.then(() => {
220-
preSyncDeletedNodeIdsCache.clear()
220+
operationPromise.then(() => {
221+
// only clear if no other operations have been done in the meantime
222+
if (lastOperationPromise === operationPromise) {
223+
preSyncDeletedNodeIdsCache.clear()
224+
}
221225
})
222226
}
223227
}

0 commit comments

Comments
 (0)