Skip to content

Commit 495d9e6

Browse files
committed
fix: retain all current nodes for the next build
1 parent ce30fc9 commit 495d9e6

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

source/node.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
import { name } from '#.';
1717

18+
import type { FullDatabase, FullPage } from '#types';
1819
import type { NodeInput, NodePluginArgs } from 'gatsby';
1920

20-
import type { FullDatabase, FullPage } from '#types';
2121

2222
interface ContentNode<Type extends string> extends NodeInput {
2323
ref: string;
@@ -93,6 +93,7 @@ export class NodeManager {
9393
await this.addNodes(this.findNewEntities(oldMap, newMap));
9494
this.updateNodes(this.findUpdatedEntities(oldMap, newMap));
9595
this.removeNodes(this.findRemovedEntities(oldMap, newMap));
96+
this.touchNodes([...newMap.values()]);
9697

9798
await this.cache.set('entityMap', [...newMap.entries()]);
9899
}
@@ -111,16 +112,6 @@ export class NodeManager {
111112
// create the node
112113
await this.createNode(node);
113114
/* eslint-enable */
114-
115-
// make sure that the node will remain in the cache
116-
this.touchNode({
117-
// since createNode mutates node, reconstruct the node input again here
118-
id: node.id,
119-
internal: {
120-
type: node.internal.type,
121-
contentDigest: node.internal.contentDigest,
122-
},
123-
});
124115
}
125116

126117
// don't be noisy if there's nothing new happen
@@ -159,6 +150,25 @@ export class NodeManager {
159150
}
160151
}
161152

153+
/**
154+
* keep all current notion nodes alive
155+
* @param entities list of current notion entities
156+
*/
157+
private touchNodes(entities: NormalisedEntity[]): void {
158+
for (const entity of entities) {
159+
const node = this.nodifyEntity(entity);
160+
this.touchNode({
161+
id: node.id,
162+
internal: {
163+
type: node.internal.type,
164+
contentDigest: node.internal.contentDigest,
165+
},
166+
});
167+
}
168+
169+
this.reporter.info(`[${name}] processed ${entities.length} nodes`);
170+
}
171+
162172
/**
163173
* create a database node
164174
* @param database a full database object

spec/node.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe('cl:NodeManager', () => {
253253
});
254254
await manager.update([updatedDatabase, ...updatedDatabase.pages]);
255255
expect(createNode).toBeCalledTimes(2);
256-
expect(touchNode).toBeCalledTimes(0);
256+
expect(touchNode).toBeCalledTimes(2);
257257
expect(deleteNode).toBeCalledTimes(1);
258258
});
259259
});

0 commit comments

Comments
 (0)