aboutsummaryrefslogtreecommitdiff
path: root/modules/calendar-sync.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-30 17:42:21 -0400
committerCraig Jennings <c@cjennings.net>2026-06-30 17:42:21 -0400
commit610fe106ad07ecc603c5c8badb11d38ce62c4c9c (patch)
treeb932d424e9ffbbcd14a641ecf3dfa3c8059ebf1c /modules/calendar-sync.el
parentdc2784b6c271bf7733259a1d5cd3657485ef7b1b (diff)
downloaddotemacs-610fe106ad07ecc603c5c8badb11d38ce62c4c9c.tar.gz
dotemacs-610fe106ad07ecc603c5c8badb11d38ce62c4c9c.zip
fix(calendar-sync): skip overlapping syncs for the same calendar
A timer tick that fired while a calendar's previous fetch was still running launched a second concurrent sync for that calendar, wasting work and racing to write the same org file. The dispatcher now skips a calendar whose status is already syncing and logs the skipped tick. The sentinel resets the status on process exit, so the skip clears on its own. load-state also clears a stale syncing status left by a crash, so a calendar can't be skipped forever.
Diffstat (limited to 'modules/calendar-sync.el')
-rw-r--r--modules/calendar-sync.el18
1 files changed, 14 insertions, 4 deletions
diff --git a/modules/calendar-sync.el b/modules/calendar-sync.el
index bc36ef90..b0bd8e38 100644
--- a/modules/calendar-sync.el
+++ b/modules/calendar-sync.el
@@ -211,10 +211,20 @@ fetcher) or :account + :calendar-id (the \\='api fetcher). Dispatches on the
:fetcher key, defaulting to the .ics path.
Updates calendar state and saves to disk on completion.
The fetch and conversion run in external processes so parsing and writing large
-calendar files do not block the interactive Emacs thread."
- (if (eq (plist-get calendar :fetcher) 'api)
- (calendar-sync--sync-calendar-api calendar)
- (calendar-sync--sync-calendar-ics calendar)))
+calendar files do not block the interactive Emacs thread.
+
+Skips a calendar whose previous sync is still in flight, so a timer tick that
+fires before a slow fetch finishes does not launch a second overlapping sync for
+the same calendar."
+ (let ((name (plist-get calendar :name)))
+ (cond
+ ((calendar-sync--syncing-p name)
+ (calendar-sync--log-silently
+ "calendar-sync: [%s] sync already in flight; skipping overlapping tick" name))
+ ((eq (plist-get calendar :fetcher) 'api)
+ (calendar-sync--sync-calendar-api calendar))
+ (t
+ (calendar-sync--sync-calendar-ics calendar)))))
(defun calendar-sync--require-calendars ()
"Return non-nil if calendars are configured, else warn and return nil."