Skip to content

Commit

Permalink
fix: persist nodes over reruns
Browse files Browse the repository at this point in the history
  • Loading branch information
alvis committed Jul 27, 2021
1 parent e683066 commit 117d20d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions source/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type NormalisedEntity<E extends FullEntity = FullEntity> = E extends any
export class NodeManager {
private createNode: NodePluginArgs['actions']['createNode'];
private deleteNode: NodePluginArgs['actions']['deleteNode'];
private touchNode: NodePluginArgs['actions']['touchNode'];
private createNodeId: NodePluginArgs['createNodeId'];
private createContentDigest: NodePluginArgs['createContentDigest'];
private cache: NodePluginArgs['cache'];
Expand All @@ -59,7 +60,7 @@ export class NodeManager {
constructor(args: NodePluginArgs) {
/* eslint-disable @typescript-eslint/unbound-method */
const {
actions: { createNode, deleteNode },
actions: { createNode, deleteNode, touchNode },
cache,
createContentDigest,
createNodeId,
Expand All @@ -70,6 +71,7 @@ export class NodeManager {
this.cache = cache;
this.createNode = createNode;
this.deleteNode = deleteNode;
this.touchNode = touchNode;
this.createNodeId = createNodeId;
this.createContentDigest = createContentDigest;
this.reporter = reporter;
Expand Down Expand Up @@ -101,7 +103,13 @@ export class NodeManager {
*/
private addNodes(added: NormalisedEntity[]): void {
for (const entity of added) {
this.createNode(this.nodifyEntity(entity));
const node = this.nodifyEntity(entity);

// make sure that the node will remain in the cache
this.touchNode(node);

// create the node
this.createNode(node);
}

// don't be noisy if there's nothing new happen
Expand Down
3 changes: 2 additions & 1 deletion spec/node.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ describe('cl:NodeManager', () => {
it('always keep gatsby synced', async () => {
const createNode = jest.fn();
const deleteNode = jest.fn();
const touchNode = jest.fn();
const createContentDigest = jest.fn(hashFn);
const createNodeId = jest.fn((id) => id);

const manager = new NodeManager({
actions: { createNode, deleteNode },
actions: { createNode, deleteNode, touchNode },
cache: caching({ store: 'memory', ttl: 0 }),
createContentDigest,
createNodeId,
Expand Down

0 comments on commit 117d20d

Please sign in to comment.