Skip to content
Merged
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
10 changes: 3 additions & 7 deletions plugins/apple-calendar/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ async fn list_system_events_for_calendars(
let filter = EventFilter {
calendar_tracking_id: calendar_tracking_id.clone(),
from: now,
to: now + chrono::Duration::days(28),
to: now + chrono::Duration::days(100),
};
Comment on lines 401 to 405
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Consolidate the 100-day window into a single constant to keep system and DB queries in lockstep

Hard-coding 100 in multiple places is brittle. Define one constant and reuse it here and in the DB filter to prevent drift.

Apply this diff within the current block:

-                to: now + chrono::Duration::days(100),
+                to: now + chrono::Duration::days(SYNC_WINDOW_DAYS),

Add this near the top of the file (after imports) to support the change:

const SYNC_WINDOW_DAYS: i64 = 100;

Run this to catch any other stale 28-day or newly hard-coded 100-day windows that should use the constant:


🏁 Script executed:

#!/bin/bash
# Find any lingering 28-day or hard-coded 100-day duration usages
rg -n -S $'Duration::days\\(\\s*28\\s*\\)|Duration::days\\(\\s*100\\s*\\)'

Length of output: 651


Consolidate hard-coded 100-day window into a single constant (fix required)

rg found multiple hard-coded uses of Duration::days(100). Replace them with a single constant to avoid drift between system and DB queries.

Files/locations to update:

  • plugins/apple-calendar/src/sync.rs — lines ~404 and ~487
  • crates/calendar-apple/src/lib.rs — lines ~315–316
  • crates/db-user/src/init.rs — lines ~738–739

Suggested changes (apply across the listed files):

  1. Prefer a single, shared constant if your workspace has a common/shared crate. Example (in that crate):
pub const SYNC_WINDOW_DAYS: i64 = 100;

Then import and use it in other crates: chrono::Duration::days(SYNC_WINDOW_DAYS).

  1. If a shared crate isn't available, add a per-crate/file constant near the imports:
const SYNC_WINDOW_DAYS: i64 = 100;
  1. Replace literals. Example diffs:

plugins/apple-calendar/src/sync.rs

-                to: now + chrono::Duration::days(100),
+                to: now + chrono::Duration::days(SYNC_WINDOW_DAYS),

plugins/apple-calendar/src/sync.rs (other occurrence)

-                end: Utc::now() + chrono::Duration::days(100),
+                end: Utc::now() + chrono::Duration::days(SYNC_WINDOW_DAYS),

crates/calendar-apple/src/lib.rs

-            from: chrono::Utc::now() - chrono::Duration::days(100),
-            to: chrono::Utc::now() + chrono::Duration::days(100),
+            from: chrono::Utc::now() - chrono::Duration::days(SYNC_WINDOW_DAYS),
+            to: chrono::Utc::now() + chrono::Duration::days(SYNC_WINDOW_DAYS),

crates/db-user/src/init.rs

-            created_at: now - chrono::Duration::days(100),
-            visited_at: now - chrono::Duration::days(100),
+            created_at: now - chrono::Duration::days(SYNC_WINDOW_DAYS),
+            visited_at: now - chrono::Duration::days(SYNC_WINDOW_DAYS),

After changes, re-run the search to confirm no remaining literals:
rg -n -S $'Duration::days\(\s100\s\)'

🤖 Prompt for AI Agents
In plugins/apple-calendar/src/sync.rs around lines 401–405 and ~487,
crates/calendar-apple/src/lib.rs around lines 315–316, and
crates/db-user/src/init.rs around lines 738–739, replace the hard-coded
chrono::Duration::days(100) occurrences with a single named constant; preferably
add a shared constant pub const SYNC_WINDOW_DAYS: i64 = 100 in a common
workspace crate and import it where needed, using
chrono::Duration::days(SYNC_WINDOW_DAYS), or if no shared crate is available
declare const SYNC_WINDOW_DAYS: i64 = 100 near the file imports in each crate
and use that constant similarly; update the imports/usages accordingly and
re-run rg -n -S $'Duration::days\\(\\s*100\\s*\\)' to confirm no remaining
literals.


// Add small delay between API calls to avoid overwhelming EventKit
Expand Down Expand Up @@ -480,11 +480,11 @@ async fn list_db_events(
.list_events(Some(ListEventFilter {
common: ListEventFilterCommon {
user_id: user_id.into(),
limit: Some(200),
limit: Some(700),
},
specific: ListEventFilterSpecific::DateRange {
start: Utc::now(),
end: Utc::now() + chrono::Duration::days(28),
end: Utc::now() + chrono::Duration::days(100),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date-range has been extended from 28 days to 100 days while the limit field on the preceding ListEventFilterCommon is still hard-coded to 200. If more than 200 events exist in a 100-day window, newer events will be silently omitted, resulting in incomplete synchronisation data. Increase the limit or calculate it dynamically to match the wider range.

Prompt for AI agents
Address the following comment on plugins/apple-calendar/src/sync.rs at line 487:

<comment>The date-range has been extended from 28 days to 100 days while the `limit` field on the preceding `ListEventFilterCommon` is still hard-coded to 200. If more than 200 events exist in a 100-day window, newer events will be silently omitted, resulting in incomplete synchronisation data. Increase the limit or calculate it dynamically to match the wider range.</comment>

<file context>
@@ -484,7 +484,7 @@ async fn list_db_events(
             },
             specific: ListEventFilterSpecific::DateRange {
                 start: Utc::now(),
-                end: Utc::now() + chrono::Duration::days(28),
+                end: Utc::now() + chrono::Duration::days(100),
             },
         }))
</file context>

},
}))
.await
Expand Down Expand Up @@ -562,28 +562,24 @@ impl CalendarSyncState {

impl EventSyncState {
async fn execute(self, db: &hypr_db_user::UserDatabase) {
// 1. Create new events first
for event in self.to_upsert {
if let Err(e) = db.upsert_event(event).await {
tracing::error!("upsert_event_error: {}", e);
}
}

// 2. Update existing events
for event in self.to_update {
if let Err(e) = db.update_event(event).await {
tracing::error!("update_event_error: {}", e);
}
}

// 3. Transfer sessions from old events to new events
for (session_id, new_event_id) in self.session_transfers {
if let Err(e) = db.session_set_event(session_id, Some(new_event_id)).await {
tracing::error!("session_transfer_error: {}", e);
}
}

// 4. Delete old events last (after sessions have been transferred)
for event in self.to_delete {
if let Err(e) = db.delete_event(&event.id).await {
tracing::error!("delete_event_error: {}", e);
Expand Down
Loading