Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ planned for 2026-01-01
- [gitignore] cleanup/simplify .gitignore (#3952, #3954, #3968, #3969)
- [compliments] refactor: optimize `loadComplimentFile` method and add unit tests(#3969)
- [core] chore: simplify Wayland start script (#3974)
- [calendar] refactor: simplify recurring event handling and event exclusion logic (#3976)

### Fixed

Expand All @@ -52,6 +53,7 @@ planned for 2026-01-01
- [weather] fixed windy icon not showing up in pirateweather (#3957)
- [compliments] fixed duplicate query param "?" when constructing refresh url (#3967)
- [compliments] fixed compliments remote file minimum delay to be 15 minutes (#3970)
- [calendar] prevent excessive fetching with smart refresh strategy (#3976)

### Updated

Expand Down
15 changes: 15 additions & 0 deletions modules/default/calendar/calendarfetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CalendarFetcher {
this.events = [];
this.reloadTimer = null;
this.serverErrorCount = 0;
this.lastFetch = null;
this.fetchFailedCallback = () => {};
this.eventsReceivedCallback = () => {};
}
Expand Down Expand Up @@ -165,6 +166,7 @@ class CalendarFetcher {
maximumEntries: this.maximumEntries,
maximumNumberOfDays: this.maximumNumberOfDays
});
this.lastFetch = Date.now();
this.broadcastEvents();
} catch (error) {
Log.error(`${this.url} - iCal parsing failed: ${error.message}`);
Expand All @@ -179,6 +181,19 @@ class CalendarFetcher {
this.scheduleNextFetch(nextDelay);
}

/**
* Check if enough time has passed since the last fetch to warrant a new one.
* Uses reloadInterval as the threshold to respect user's configured fetchInterval.
* @returns {boolean} True if a new fetch should be performed
*/
shouldRefetch () {
if (!this.lastFetch) {
return true;
}
const timeSinceLastFetch = Date.now() - this.lastFetch;
return timeSinceLastFetch >= this.reloadInterval;
}

/**
* Broadcasts the current events to listeners
*/
Expand Down
Loading