File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ export const DEFAULT_TTL: NotionTTL = {
71
71
pageContent : 0 ,
72
72
} ;
73
73
74
+ const ONE_MINUTE = 60000 ;
75
+
74
76
/** A simple Notion client */
75
77
export class Notion {
76
78
private cache : Cache ;
@@ -277,7 +279,12 @@ export class Notion {
277
279
const cacheKey = `page:${ page . id } :content` ;
278
280
const cachedPage = await this . cache . get < FullPage > ( cacheKey ) ;
279
281
280
- if ( cachedPage && cachedPage . last_edited_time === page . last_edited_time ) {
282
+ if (
283
+ cachedPage &&
284
+ cachedPage . last_edited_time === page . last_edited_time &&
285
+ // don't use the cache if the last edited time happened to be the last minute since Notion rounded the time resolution to minute level recently
286
+ Date . now ( ) - new Date ( page . last_edited_time ) . getTime ( ) > ONE_MINUTE
287
+ ) {
281
288
return cachedPage ;
282
289
} else {
283
290
const normalisedPage = await this . normalisePage ( page ) ;
Original file line number Diff line number Diff line change 13
13
* -------------------------------------------------------------------------
14
14
*/
15
15
16
+ import { createHash } from 'crypto' ;
17
+
16
18
import { name } from '#.' ;
17
19
18
20
import type { NodeInput , NodePluginArgs } from 'gatsby' ;
@@ -39,6 +41,7 @@ type NormalisedEntity<E extends FullEntity = FullEntity> = E extends any
39
41
? Omit < E , 'parent' > & {
40
42
parent : Link | null ;
41
43
children : Link [ ] ;
44
+ digest : string ;
42
45
}
43
46
: never ;
44
47
@@ -189,10 +192,7 @@ export class NodeManager {
189
192
this . createNodeId ( `${ object } :${ id } ` ) ,
190
193
) ,
191
194
internal : {
192
- contentDigest : this . createContentDigest ( {
193
- id : entity . id ,
194
- lastEditedTime : entity . last_edited_time ,
195
- } ) ,
195
+ contentDigest : entity . digest ,
196
196
...internal ,
197
197
} ,
198
198
} ;
@@ -254,10 +254,7 @@ export class NodeManager {
254
254
255
255
for ( const [ id , newEntity ] of newMap . entries ( ) ) {
256
256
const oldEntity = oldMap . get ( id ) ;
257
- if (
258
- oldEntity &&
259
- oldEntity . last_edited_time !== newEntity . last_edited_time
260
- ) {
257
+ if ( oldEntity && oldEntity . digest !== newEntity . digest ) {
261
258
updated . push ( newEntity ) ;
262
259
}
263
260
}
@@ -298,6 +295,7 @@ export function computeEntityMap(
298
295
...entity ,
299
296
parent : normaliseParent ( entity . parent ) ,
300
297
children : [ ] ,
298
+ digest : createHash ( 'sha256' ) . update ( JSON . stringify ( entity ) ) . digest ( 'hex' ) ,
301
299
} ) ;
302
300
}
303
301
Original file line number Diff line number Diff line change @@ -241,7 +241,7 @@ describe('cl:NodeManager', () => {
241
241
] ,
242
242
} ) ;
243
243
await manager . update ( [ updatedDatabase , ...updatedDatabase . pages ] ) ;
244
- expect ( createNode ) . toBeCalledTimes ( 1 ) ;
244
+ expect ( createNode ) . toBeCalledTimes ( 2 ) ;
245
245
expect ( deleteNode ) . toBeCalledTimes ( 1 ) ;
246
246
} ) ;
247
247
} ) ;
You can’t perform that action at this time.
0 commit comments