Kristjan ESPERANTO c2ec6fc2b9 [calendar] fix: prevent excessive fetching on client reload and refactor calendarfetcherutils.js (#3976)
The bottom line of this PR is, that it fixes an issue and simplifies the
code by dealing with the TODOs in the code.

For review, I suggest looking at each commit individually. If there are
too many changes for a PR, let me know and I'll split it up
🙂

## 1. [fix(calendar): prevent excessive fetching with smart refresh
strategy](8892cd3d5a)

- Add lastFetch timestamp tracking to CalendarFetcher
- Add shouldRefetch() method with configurable minimum interval
(default: 3 minutes)
- When reusing existing fetcher: fetch if data is stale (>3 min),
otherwise broadcast cached events
- Prevents double broadcasts to consuming modules while maintaining
fresh data
- Balances rate limit prevention (Issue
https://github.com/MagicMirrorOrg/MagicMirror/issues/3971) with data
freshness on user reload
- Prevents excessive fetching during rapid reloads (e.g., Fully Kiosk
screensaver use case)
- Allows fresh calendar data when enough time has passed since last
fetch

## 2. [refactor(calendar): simplify event exclusion
logic](d507aba82d)

- Extract filtering logic from `shouldEventBeExcluded` into new helper
`checkEventAgainstFilter`
- Simplify the main loop in `shouldEventBeExcluded

It resolves a TODO from the comments in the code:
* `This seems like an overly complicated way to exclude events based on
the title.`

## 3. [refactor(calendar): extract recurring event expansion
logic](d510160bd2)

This change separates the expansion of recurring events from the main
filtering loop into a new helper function 'expandRecurringEvent'.

It resolves two TODOs from the comments in the code:
- `This should be a separate function`
- `This should create an event per moment so we can change anything we
want`

This improves code readability, reduces complexity in 'filterEvents',
and allows for cleaner handling of individual recurrence instances.

## 4. [refactor(calendar): simplify recurring event
handling](b04f716cc0)

- Simplify 'getMomentsFromRecurringEvent' using modern syntax
- Improve handling of full-day events across different timezones


## 5. [test(calendar): fix UNTIL date in fullday_until.ics
fixture](1d762b2ade)

The issue was with the UNTIL date being May 4th while DTSTART was May
5th. This created an invalid recurrence rule where the end date came
before the start date.

The fix only adjusts the UNTIL date from May 4th to May 5th, so it
matches the start date.
2025-12-08 10:07:04 +01:00
2025-01-08 11:46:42 +01:00
2023-07-01 21:17:31 +02:00
2024-03-16 13:06:27 +01:00
2020-05-11 22:22:32 +02:00
2025-09-30 18:14:08 +02:00
2024-03-28 12:37:18 +01:00
2023-10-01 20:13:41 +02:00

MagicMirror²: The open source modular smart mirror platform.

License GitHub Actions Build Status GitHub Stars

MagicMirror² is an open source modular smart mirror platform. With a growing list of installable modules, the MagicMirror² allows you to convert your hallway or bathroom mirror into your personal assistant. MagicMirror² is built by the creator of the original MagicMirror with the incredible help of a growing community of contributors.

MagicMirror² focuses on a modular plugin system and uses Electron as an application wrapper. So no more web server or browser installs necessary!

Documentation

For the full documentation including installation instructions, please visit our dedicated documentation website: https://docs.magicmirror.builders.

Contributing Guidelines

Contributions of all kinds are welcome, not only in the form of code but also with regards to

  • bug reports
  • documentation
  • translations

For the full contribution guidelines, check out: https://docs.magicmirror.builders/about/contributing.html

Enjoying MagicMirror? Consider a donation!

MagicMirror² is Open Source and free. That doesn't mean we don't need any money.

Please consider a donation to help us cover the ongoing costs like webservers and email services. If we receive enough donations we might even be able to free up some working hours and spend some extra time improving the MagicMirror² core.

To donate, please follow this link.

MagPi Top 50

Description
MagicMirror² is an open source modular smart mirror platform. With a growing list of installable modules, the MagicMirror² allows you to convert your hallway or bathroom mirror into your personal assistant.
Readme 100 MiB
Languages
JavaScript 89.2%
CSS 8%
Nunjucks 2.2%
HTML 0.4%
TypeScript 0.2%