Fix cache issue with handling more than 500 records

This commit is contained in:
Aleksander Machniak 2023-05-03 10:31:53 +02:00
parent d711a32fab
commit f70c6d3508
3 changed files with 9 additions and 29 deletions

View file

@ -761,17 +761,17 @@ class kolab_storage_cache
* Select Kolab objects filtered by the given query
*
* @param array Pseudo-SQL query as list of filter parameter triplets
* triplet: array('<colname>', '<comparator>', '<value>')
* @param boolean Set true to only return UIDs instead of complete objects
* @param boolean Use fast mode to fetch only minimal set of information
* (no xml fetching and parsing, etc.)
* triplet: array('<colname>', '<comparator>', '<value>')
* @param bool Set true to only return UIDs instead of complete objects
* @param bool Use fast mode to fetch only minimal set of information
* (no xml fetching and parsing, etc.)
*
* @return array List of Kolab data objects (each represented as hash array) or UIDs
* @return null|array|kolab_storage_dataset List of Kolab data objects
* (each represented as hash array) or UIDs
*/
public function select($query = array(), $uids = false, $fast = false)
{
$result = $uids ? array() : new kolab_storage_dataset($this);
$count = null;
// read from local cache DB (assume it to be synchronized)
if ($this->ready) {
@ -780,11 +780,6 @@ class kolab_storage_cache
// fetch full object data unless only uids are requested
$fetchall = !$uids;
// skip SELECT if we know it will return nothing
if ($count === 0) {
return $result;
}
$sql_query = "SELECT " . ($fetchall ? '*' : "`msguid` AS `_msguid`, `uid`")
. " FROM `{$this->cache_table}` WHERE `folder_id` = ?"
. $this->_sql_where($query)

View file

@ -26,7 +26,7 @@
class kolab_storage_config
{
const FOLDER_TYPE = 'configuration';
const MAX_RELATIONS = 499; // should be less than kolab_storage_cache::MAX_RECORDS
const MAX_RELATIONS = 499;
/**
* Singleton instace of kolab_storage_config

View file

@ -414,19 +414,10 @@ class kolab_storage_dav_cache extends kolab_storage_cache
public function select($query = [], $uids = false, $fast = false)
{
$result = $uids ? [] : new kolab_storage_dataset($this);
$count = null;
$this->_read_folder_data();
// fetch full object data on one query if a small result set is expected
$fetchall = !$uids && ($this->limit ? $this->limit[0] : ($count = $this->count($query))) < self::MAX_RECORDS;
// skip SELECT if we know it will return nothing
if ($count === 0) {
return $result;
}
$sql_query = "SELECT " . ($fetchall ? '*' : "`uid`")
$sql_query = "SELECT " . ($uids ? "`uid`" : '*')
. " FROM `{$this->cache_table}` WHERE `folder_id` = ?"
. $this->_sql_where($query)
. (!empty($this->order_by) ? " ORDER BY " . $this->order_by : '');
@ -445,13 +436,7 @@ class kolab_storage_dav_cache extends kolab_storage_cache
}
while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
if ($uids) {
$result[] = $sql_arr['uid'];
}
else if (!$fetchall) {
$result[] = $sql_arr;
}
else if (($object = $this->_unserialize($sql_arr, true, $fast))) {
if (!$uids && ($object = $this->_unserialize($sql_arr, true, $fast))) {
$result[] = $object;
}
else {