@@ -50,9 +50,8 @@ export default {
5050 for await ( const page of pagesStream ) {
5151 propertyValues [ page . id ] = { } ;
5252 for ( const propertyName of properties ) {
53- const pageProperty = page . properties [ propertyName ] ;
54- this . maybeRemoveFileSubItems ( pageProperty ) ;
55- propertyValues [ page . id ] [ propertyName ] = md5 ( JSON . stringify ( pageProperty ) ) ;
53+ const hash = this . calculateHash ( page . properties [ propertyName ] ) ;
54+ propertyValues [ page . id ] [ propertyName ] = hash ;
5655 }
5756 lastUpdatedTimestamp = Math . max (
5857 lastUpdatedTimestamp ,
@@ -82,6 +81,11 @@ export default {
8281 const { properties } = await this . notion . retrieveDatabase ( this . databaseId ) ;
8382 return Object . keys ( properties ) ;
8483 } ,
84+ calculateHash ( property ) {
85+ const clone = JSON . parse ( JSON . stringify ( property ) ) ;
86+ this . maybeRemoveFileSubItems ( clone ) ;
87+ return md5 ( JSON . stringify ( clone ) ) ;
88+ } ,
8589 maybeRemoveFileSubItems ( property ) {
8690 // Files & Media type:
8791 // `url` and `expiry_time` are constantly updated by Notion, so ignore these fields
@@ -133,14 +137,13 @@ export default {
133137
134138 let propertyChangeFound = false ;
135139 for ( const propertyName of properties ) {
136- const pageProperty = JSON . parse ( JSON . stringify ( page . properties [ propertyName ] ) ) ;
137- this . maybeRemoveFileSubItems ( pageProperty ) ;
138- const currentProperty = md5 ( JSON . stringify ( pageProperty ) ) ;
139- if ( ! propertyValues [ page . id ] || currentProperty !== propertyValues [ page . id ] [ propertyName ] ) {
140+ const hash = this . calculateHash ( page . properties [ propertyName ] ) ;
141+ const dbValue = propertyValues [ page . id ] [ propertyName ] ;
142+ if ( ! propertyValues [ page . id ] || hash !== dbValue ) {
140143 propertyChangeFound = true ;
141144 propertyValues [ page . id ] = {
142145 ...propertyValues [ page . id ] ,
143- [ propertyName ] : currentProperty ,
146+ [ propertyName ] : hash ,
144147 } ;
145148 }
146149 }
0 commit comments