15
15
16
16
import { name } from '#.' ;
17
17
18
+ import type { FullDatabase , FullPage } from '#types' ;
18
19
import type { NodeInput , NodePluginArgs } from 'gatsby' ;
19
20
20
- import type { FullDatabase , FullPage } from '#types' ;
21
21
22
22
interface ContentNode < Type extends string > extends NodeInput {
23
23
ref : string ;
@@ -93,6 +93,7 @@ export class NodeManager {
93
93
await this . addNodes ( this . findNewEntities ( oldMap , newMap ) ) ;
94
94
this . updateNodes ( this . findUpdatedEntities ( oldMap , newMap ) ) ;
95
95
this . removeNodes ( this . findRemovedEntities ( oldMap , newMap ) ) ;
96
+ this . touchNodes ( [ ...newMap . values ( ) ] ) ;
96
97
97
98
await this . cache . set ( 'entityMap' , [ ...newMap . entries ( ) ] ) ;
98
99
}
@@ -111,16 +112,6 @@ export class NodeManager {
111
112
// create the node
112
113
await this . createNode ( node ) ;
113
114
/* 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
- } ) ;
124
115
}
125
116
126
117
// don't be noisy if there's nothing new happen
@@ -159,6 +150,25 @@ export class NodeManager {
159
150
}
160
151
}
161
152
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
+
162
172
/**
163
173
* create a database node
164
174
* @param database a full database object
0 commit comments