Skip to content

Commit 9c25b15

Browse files
authored
add checksum to test whether calendar event list changed (#3988)
for issue #3971 add checksum to test if event list changed to reduce/eliminate no change screen update fixes #3971 crc32 checksum created in node helper, easy require, vs trying to do in browser. added to socket notification payload, used in browser
1 parent c64d3ef commit 9c25b15

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

modules/default/calendar/calendar.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,27 @@ Module.register("calendar", {
184184

185185
if (notification === "CALENDAR_EVENTS") {
186186
if (this.hasCalendarURL(payload.url)) {
187-
this.calendarData[payload.url] = payload.events;
187+
// have we received events for this url
188+
if (!this.calendarData[payload.url]) {
189+
// no, setup the structure to hold the info
190+
this.calendarData[payload.url] = { events: null, checksum: null };
191+
}
192+
// save the event list
193+
this.calendarData[payload.url].events = payload.events;
194+
188195
this.error = null;
189196
this.loaded = true;
190197

191198
if (this.config.broadcastEvents) {
192199
this.broadcastEvents();
193200
}
201+
// if the checksum is the same
202+
if (this.calendarData[payload.url].checksum === payload.checksum) {
203+
// then don't update the UI
204+
return;
205+
}
206+
// haven't seen or the checksum is different
207+
this.calendarData[payload.url].checksum = payload.checksum;
194208

195209
if (!this.config.updateOnFetch) {
196210
if (this.calendarDisplayer[payload.url] === undefined) {
@@ -602,7 +616,7 @@ Module.register("calendar", {
602616
let events = [];
603617

604618
for (const calendarUrl in this.calendarData) {
605-
const calendar = this.calendarData[calendarUrl];
619+
const calendar = this.calendarData[calendarUrl].events;
606620
let remainingEntries = this.maximumEntriesForUrl(calendarUrl);
607621
let maxPastDaysCompare = now.clone().subtract(this.maximumPastDaysForUrl(calendarUrl), "days");
608622
let by_url_calevents = [];

modules/default/calendar/node_helper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const zlib = require("node:zlib");
12
const NodeHelper = require("node_helper");
23
const Log = require("logger");
34
const CalendarFetcher = require("./calendarfetcher");
@@ -90,10 +91,12 @@ module.exports = NodeHelper.create({
9091
* @param {string} identifier the identifier of the calendar
9192
*/
9293
broadcastEvents (fetcher, identifier) {
94+
const checksum = zlib.crc32(Buffer.from(JSON.stringify(fetcher.events), "utf8"));
9395
this.sendSocketNotification("CALENDAR_EVENTS", {
9496
id: identifier,
9597
url: fetcher.url,
96-
events: fetcher.events
98+
events: fetcher.events,
99+
checksum: checksum
97100
});
98101
}
99102
});

0 commit comments

Comments
 (0)