* CalDAV: fixed and enabled iterator again, to minimize resource usage, fix for mystylite bug #1942

it was disabled because sql query was broken, because we did not use MIN(cal_end) multiple events per cal_id were returned
This commit is contained in:
Ralf Becker 2011-08-03 16:13:56 +00:00
parent 5f415cafc2
commit 17f6dad7eb
2 changed files with 12 additions and 21 deletions

View File

@ -172,13 +172,12 @@ class calendar_groupdav extends groupdav_handler
}
}
}
/* disabling not working iterator
// return iterator, calling ourself to return result in chunks
$files['files'] = new groupdav_propfind_iterator($this,$path,$filter,$files['files']);
return true;
}
*/
/**
* Callback for profind interator
*
@ -187,16 +186,13 @@ class calendar_groupdav extends groupdav_handler
* @param array|boolean $start=false false=return all or array(start,num)
* @return array with "files" array with values for keys path and props
*/
/* disabling not working iterator
function propfind_callback($path,array $filter,$start=false)
function propfind_callback($path,array $filter,$start=false)
{
*/
if ($this->debug) $starttime = microtime(true);
$calendar_data = $filter['calendar_data'];
unset($filter['calendar_data']);
/* disabling not working iterator
$files = array();
if (is_array($start))
@ -204,7 +200,6 @@ class calendar_groupdav extends groupdav_handler
$filter['offset'] = $start[0];
$filter['num_rows'] = $start[1];
}
*/
$events =& $this->bo->search($filter);
if ($events)
{
@ -245,12 +240,9 @@ class calendar_groupdav extends groupdav_handler
{
$props[] = HTTP_WebDAV_Server::mkprop('getcontentlength', ''); // expensive to calculate and no CalDAV client uses it
}
/* disabling not working iterator
$files[] = array(
*/
$files['files'][] = array(
'path' => $path.$this->get_path($event),
'props' => $props,
'path' => $path.$this->get_path($event),
'props' => $props,
);
}
}
@ -259,10 +251,7 @@ class calendar_groupdav extends groupdav_handler
error_log(__METHOD__."($path) took ".(microtime(true) - $starttime).
' to return '.count($files['files']).' items');
}
/* disabling not working iterator
return $files;
*/
return true;
}
/**

View File

@ -428,7 +428,8 @@ class calendar_so
$users_by_type[$user[0]][] = (int) substr($user,1);
}
}
$to_or = $user_or = $owner_or = array();
$to_or = $user_or = array();
$owner_or = null;
$useUnionQuery = $this->db->capabilities['distinct_on_text'] && $this->db->capabilities['union'];
$table_def = $this->db->get_table_definitions('calendar',$this->user_table);
foreach($users_by_type as $type => $ids)
@ -441,10 +442,10 @@ class calendar_so
),' AND '.$this->user_table.'.',array(
'cal_user_id' => $ids,
));
if ($type == 'u' && ($filter == 'owner'))
if ($type == 'u' && $filter == 'owner')
{
$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
$owner_or[] = $this->db->expression($cal_table_def,array('cal_owner' => $ids));
$owner_or = $this->db->expression($cal_table_def,array('cal_owner' => $ids));
}
}
else
@ -511,11 +512,12 @@ class calendar_so
$where[] = (int)$start.' < (CASE WHEN recur_type IS NULL THEN cal_end ELSE (CASE WHEN recur_enddate!=0 THEN recur_enddate ELSE 9999999999 END) END)';
}
}
// if not enum recuring events, we have to use minimum start- AND end-dates, otherwise we get more then one event per cal_id!
if (!$params['enum_recuring'])
{
$where[] = "$this->user_table.cal_recur_date=0";
$group_by = 'GROUP BY '.str_replace('cal_start,','',implode(', ',(array)$cols));
$cols = str_replace('cal_start','MIN(cal_start) AS cal_start',$cols);
$group_by = 'GROUP BY '.str_replace(array('cal_start,','cal_end,'),'',implode(', ',(array)$cols));
$cols = str_replace(array('cal_start','cal_end'),array('MIN(cal_start) AS cal_start','MIN(cal_end) AS cal_end'),$cols);
}
if ($end) $where[] = 'cal_start < '.(int)$end;
@ -553,7 +555,7 @@ class calendar_so
$selects = array();
// we check if there are parts to use for the construction of our UNION query,
// as replace the OR by construction of a suitable UNION for performance reasons
if (!empty($owner_or)||!empty($user_or))
if ($owner_or || $user_or)
{
foreach($user_or as $user_sql)
{