Performance: Use initialized calendars if available, skipping redundant folder cache synchronization

This commit is contained in:
Aleksander Machniak 2016-02-22 11:37:34 +01:00
parent a7e3a938a7
commit cb7f4d635b
2 changed files with 22 additions and 10 deletions

View file

@ -346,14 +346,17 @@ class kolab_driver extends calendar_driver
$this->_read_calendars(); $this->_read_calendars();
// create calendar object if necesary // create calendar object if necesary
if (!$this->calendars[$id] && in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) { if (!$this->calendars[$id]) {
if (in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
$this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal); $this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal);
} }
else if (!$this->calendars[$id] && $id !== self::BIRTHDAY_CALENDAR_ID) { else if ($id !== self::BIRTHDAY_CALENDAR_ID) {
$calendar = kolab_calendar::factory($id, $this->cal); $calendar = kolab_calendar::factory($id, $this->cal);
if ($calendar->ready) if ($calendar->ready) {
$this->calendars[$calendar->id] = $calendar; $this->calendars[$calendar->id] = $calendar;
} }
}
}
return $this->calendars[$id]; return $this->calendars[$id];
} }

View file

@ -197,7 +197,7 @@ class kolab_invitation_calendar
else { else {
$cal = null; $cal = null;
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
$cal = new kolab_calendar($foldername, $this->cal); $cal = $this->_get_calendar($foldername);
if ($cal->ready && $cal->storage && $cal->get_event($event['id'])) { if ($cal->ready && $cal->storage && $cal->get_event($event['id'])) {
break; break;
} }
@ -233,7 +233,7 @@ class kolab_invitation_calendar
// aggregate events from all calendar folders // aggregate events from all calendar folders
$events = array(); $events = array();
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
$cal = new kolab_calendar($foldername, $this->cal); $cal = $this->_get_calendar($foldername);
if ($cal->get_namespace() == 'other') if ($cal->get_namespace() == 'other')
continue; continue;
@ -287,7 +287,7 @@ class kolab_invitation_calendar
// aggregate counts from all calendar folders // aggregate counts from all calendar folders
$count = 0; $count = 0;
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) { foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
$cal = new kolab_calendar($foldername, $this->cal); $cal = $this->_get_calendar($foldername);
if ($cal->get_namespace() == 'other') if ($cal->get_namespace() == 'other')
continue; continue;
@ -297,6 +297,15 @@ class kolab_invitation_calendar
return $count; return $count;
} }
/**
* Get calendar object instance (that maybe already initialized)
*/
private function _get_calendar($folder_name)
{
$id = kolab_storage::folder_id($folder_name, true);
return $this->cal->driver->get_calendar($id);
}
/** /**
* Helper method to modify some event properties * Helper method to modify some event properties
*/ */