Skip to content

Commit

Permalink
fix race
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Oct 19, 2021
1 parent 02321d9 commit 23b2620
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/gatsby/src/datastore/lmdb/lmdb-datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,11 @@ function updateDataStore(action: ActionsUnion): void {
case `ADD_CHILD_NODE_TO_PARENT_NODE`:
case `MATERIALIZE_PAGE_MODE`: {
const dbs = getDatabases()
lastOperationPromise = Promise.all([
const operationPromise = Promise.all([
updateNodes(dbs.nodes, action),
updateNodesByType(dbs.nodesByType, action),
])
lastOperationPromise = operationPromise

// if create is used in the same transaction as delete we should remove it from cache
if (action.type === `CREATE_NODE`) {
Expand All @@ -216,8 +217,11 @@ function updateDataStore(action: ActionsUnion): void {
preSyncDeletedNodeIdsCache.add(
((action as IDeleteNodeAction).payload as IGatsbyNode).id
)
lastOperationPromise.then(() => {
preSyncDeletedNodeIdsCache.clear()
operationPromise.then(() => {
// only clear if no other operations have been done in the meantime
if (lastOperationPromise === operationPromise) {
preSyncDeletedNodeIdsCache.clear()
}
})
}
}
Expand Down

0 comments on commit 23b2620

Please sign in to comment.