1515
1616import { name } from '#.' ;
1717
18+ import type { FullDatabase , FullPage } from '#types' ;
1819import type { NodeInput , NodePluginArgs } from 'gatsby' ;
1920
20- import type { FullDatabase , FullPage } from '#types' ;
2121
2222interface 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
0 commit comments