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
27 changes: 24 additions & 3 deletions core/events/EventStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
* @param {import('../../types.js').QueryFilters} [filters={}] - Query filters
* @returns {Event[]} Filtered events
*/
queryEvents(filters = {}) {

Check warning on line 214 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / Code Complexity

Method 'queryEvents' has a complexity of 20. Maximum allowed is 15
let results = Array.from(this.events.values());

// Filter by date range
Expand All @@ -234,9 +234,30 @@

// Filter by month
if (filters.month && filters.year) {
const monthKey = `${filters.year}-${String(filters.month).padStart(2, '0')}`;
const eventIds = this.indices.byMonth.get(monthKey) || new Set();
results = results.filter(event => eventIds.has(event.id));
// Collect candidates from target month AND adjacent months to handle
// timezone boundary issues (events indexed in the event's own timezone
// may fall in a different month than the query month)
const candidateIds = new Set();
for (let offset = -1; offset <= 1; offset++) {
let m = filters.month + offset;
let y = filters.year;
if (m < 1) { m = 12; y--; }
if (m > 12) { m = 1; y++; }
const key = `${y}-${String(m).padStart(2, '0')}`;
const ids = this.indices.byMonth.get(key);
if (ids) {
ids.forEach(id => candidateIds.add(id));
}
}

// Post-filter: only include events that actually overlap with the requested month
const monthStart = new Date(filters.year, filters.month - 1, 1);
const monthEnd = new Date(filters.year, filters.month, 0, 23, 59, 59, 999);

results = results.filter(event => {
if (!candidateIds.has(event.id)) return false;
return event.start <= monthEnd && event.end >= monthStart;
});
}

// Filter by all-day events
Expand Down Expand Up @@ -308,7 +329,7 @@
timezone = timezone || this.defaultTimezone;

// Use local date string for the query date (in the calendar's timezone)
const dateStr = DateUtils.getLocalDateString(date);

Check warning on line 332 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / ESLint

'dateStr' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 332 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / Code Complexity

'dateStr' is assigned a value but never used. Allowed unused vars must match /^_/u

// Collect candidate event IDs from indices
const candidateIds = new Set();
Expand Down Expand Up @@ -683,8 +704,8 @@
});

// Index by month(s) using UTC
const startMonth = `${startDate.getFullYear()}-${String(startDate.getMonth() + 1).padStart(2, '0')}`;

Check warning on line 707 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / ESLint

'startMonth' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 707 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / Code Complexity

'startMonth' is assigned a value but never used. Allowed unused vars must match /^_/u
const endMonth = `${endDate.getFullYear()}-${String(endDate.getMonth() + 1).padStart(2, '0')}`;

Check warning on line 708 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / ESLint

'endMonth' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 708 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / Code Complexity

'endMonth' is assigned a value but never used. Allowed unused vars must match /^_/u

// Add to all months the event spans
const currentMonth = new Date(startDate.getFullYear(), startDate.getMonth(), 1);
Expand Down Expand Up @@ -729,7 +750,7 @@
*/
_indexEventLazy(event) {
// Create lazy index markers
const markers = this.optimizer.createLazyIndexMarkers(event);

Check warning on line 753 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / ESLint

'markers' is assigned a value but never used. Allowed unused vars must match /^_/u

Check warning on line 753 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / Code Complexity

'markers' is assigned a value but never used. Allowed unused vars must match /^_/u

// Index only the boundaries initially (in event's local timezone)
const eventStartLocal = event.getStartInTimezone(event.timeZone);
Expand Down Expand Up @@ -1123,7 +1144,7 @@
cutoffDate.setMonth(cutoffDate.getMonth() - 6); // Default: 6 months ago
}

const cutoffStr = cutoffDate.toDateString();

Check warning on line 1147 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / ESLint

'cutoffStr' is assigned a value but never used. Allowed unused vars must match /^_/u
let removed = 0;

// Clean up date indices
Expand All @@ -1147,7 +1168,7 @@
}
}

console.log(`Optimized indices: removed ${removed} old date entries`);

Check warning on line 1171 in core/events/EventStore.js

View workflow job for this annotation

GitHub Actions / ESLint

Unexpected console statement
return removed;
}

Expand Down
Loading