@@ -4,6 +4,7 @@ const appMessage = require('./app-messages'),
44 ErrorResponse = require ( './error-response' ) ,
55 getDayjs = require ( './dayjs-wrapper' ) ,
66 initResource = require ( './init-resource' ) ,
7+ jsonStore = require ( './json-store' ) ,
78 logEvent = require ( './log-event' ) ,
89 mongodb = require ( './mongodb' ) ,
910 notifySubscribers = require ( './notify-subscribers' ) ;
@@ -56,13 +57,7 @@ async function checkForResourceChange(resource, resourceUrl, startticks) {
5657
5758 const hash = md5Hash ( body ) ;
5859
59- if ( resource . lastHash !== hash ) {
60- resource . flDirty = true ;
61- } else if ( resource . lastSize !== body . length ) {
62- resource . flDirty = true ;
63- } else {
64- resource . flDirty = false ;
65- }
60+ const changed = ( resource . lastHash !== hash ) || ( resource . lastSize !== body . length ) ;
6661
6762 resource . lastHash = hash ;
6863 resource . lastSize = body . length ;
@@ -71,7 +66,7 @@ async function checkForResourceChange(resource, resourceUrl, startticks) {
7166 'Ping' ,
7267 {
7368 resourceUrl : resourceUrl ,
74- changed : resource . flDirty ,
69+ changed : changed ,
7570 hash : resource . lastHash ,
7671 size : resource . lastSize ,
7772 stats : {
@@ -81,6 +76,8 @@ async function checkForResourceChange(resource, resourceUrl, startticks) {
8176 } ,
8277 startticks
8378 ) ;
79+
80+ return changed ;
8481}
8582
8683async function fetchResource ( resourceUrl ) {
@@ -101,10 +98,11 @@ async function upsertResource(resource) {
10198 resource ,
10299 { upsert : true }
103100 ) ;
101+ jsonStore . setResource ( resource . _id , resource ) ;
104102}
105103
106- async function notifySubscribersIfDirty ( resource , resourceUrl ) {
107- if ( resource . flDirty ) {
104+ async function notifySubscribersIfDirty ( changed , resource , resourceUrl ) {
105+ if ( changed ) {
108106 const dayjs = await getDayjs ( ) ;
109107 resource . ctUpdates += 1 ;
110108 resource . whenLastUpdate = new Date ( dayjs ( ) . utc ( ) . format ( ) ) ;
@@ -120,8 +118,8 @@ async function ping(resourceUrl) {
120118 ) ;
121119
122120 await checkPingFrequency ( resource ) ;
123- await checkForResourceChange ( resource , resourceUrl , startticks ) ;
124- await notifySubscribersIfDirty ( resource , resourceUrl ) ;
121+ const changed = await checkForResourceChange ( resource , resourceUrl , startticks ) ;
122+ await notifySubscribersIfDirty ( changed , resource , resourceUrl ) ;
125123 await upsertResource ( resource ) ;
126124
127125 return {
0 commit comments