Skip to content

Commit

Permalink
fix: time range is ignored in 'fastQuery' - #565
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMosin committed Nov 28, 2024
1 parent f954327 commit f750e33
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/Backend/BCSabreImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,24 +1296,24 @@ private function fastQuery(array $calIds, int $startTs, int $endTs, array $propF
));
}

if ($startTs > 0) {
$query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($startTs)));
}
if ($endTs > 0) {
$query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($endTs)));
}

$query->select(['c.calendardata'])
->from('calendarobjects', 'c')
->where($calendarsOrExpr)
->andWhere($query->expr()->neq('c.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_PRIVATE)))
->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter('VEVENT')))
->andWhere($query->expr()->isNull('c.deleted_at'))
->setMaxResults(1024);
->setMaxResults(1024 * count($calIds));
foreach ($additionalColumns as $column) {
$query->addSelect('c.' . $column);
}

if ($startTs > 0) {
$query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($startTs)));
}
if ($endTs > 0) {
$query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($endTs)));
}

if (($cnt = count($propFilters)) > 0) {
for ($i = 0; $i < $cnt; $i++) {
$jn = 'j' . $i;
Expand Down
38 changes: 38 additions & 0 deletions tests/calendar_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from icalendar import Calendar, Event
from datetime import datetime, timedelta
import random
import pytz

cal = Calendar()
cal.add('prodid', '-//Test Calendar Generator//EN')
cal.add('version', '2.0')
cal.add('calscale', 'GREGORIAN')

def random_string(length):
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
return ''.join(random.choice(chars) for _ in range(length))

utc = pytz.UTC

start_date = datetime.now(utc) - timedelta(days=1)

for _ in range(1500):
event = Event()

event_start = start_date + timedelta(days=random.randint(0, 21), hours=random.randint(0, 23), minutes=random.randint(0, 59))
event_end = event_start + timedelta(hours=random.randint(1, 3))

event.add('uid', f"{random_string(32)}@example.com")
event.add('dtstamp', datetime.now(utc))
event.add('summary', random_string(10))
event.add('description', random_string(50))
event.add('dtstart', event_start)
event.add('dtend', event_end)

cal.add_component(event)

file_path = 'test_calendar.ics'
with open(file_path, 'wb') as f:
f.write(cal.to_ical())

print(f"Calendar saved to {file_path}")

0 comments on commit f750e33

Please sign in to comment.