Improve performance of kolab_storage_folder object creation when
folder type is already known (e.g. in kolab_storage::get_folders())
This commit is contained in:
parent
4ed6758112
commit
a2e191d631
2 changed files with 28 additions and 23 deletions
|
@ -72,11 +72,11 @@ class kolab_storage
|
||||||
*/
|
*/
|
||||||
public static function get_folders($type)
|
public static function get_folders($type)
|
||||||
{
|
{
|
||||||
$folders = array();
|
$folders = $folderdata = array();
|
||||||
|
|
||||||
if (self::setup()) {
|
if (self::setup()) {
|
||||||
foreach ((array)self::list_folders('', '*', $type) as $foldername) {
|
foreach ((array)self::list_folders('', '*', $type, false, $folderdata) as $foldername) {
|
||||||
$folders[$foldername] = new kolab_storage_folder($foldername, self::$imap);
|
$folders[$foldername] = new kolab_storage_folder($foldername, $folderdata[$foldername]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class kolab_storage
|
||||||
*/
|
*/
|
||||||
public static function get_folder($folder)
|
public static function get_folder($folder)
|
||||||
{
|
{
|
||||||
return self::setup() ? new kolab_storage_folder($folder, self::$imap) : null;
|
return self::setup() ? new kolab_storage_folder($folder) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class kolab_storage
|
||||||
$folder = null;
|
$folder = null;
|
||||||
foreach ((array)self::list_folders('', '*', $type) as $foldername) {
|
foreach ((array)self::list_folders('', '*', $type) as $foldername) {
|
||||||
if (!$folder)
|
if (!$folder)
|
||||||
$folder = new kolab_storage_folder($foldername, self::$imap);
|
$folder = new kolab_storage_folder($foldername);
|
||||||
else
|
else
|
||||||
$folder->set_folder($foldername);
|
$folder->set_folder($foldername);
|
||||||
|
|
||||||
|
@ -384,10 +384,11 @@ class kolab_storage
|
||||||
* @param string Optional name pattern
|
* @param string Optional name pattern
|
||||||
* @param string Data type to list folders for (contact,distribution-list,event,task,note,mail)
|
* @param string Data type to list folders for (contact,distribution-list,event,task,note,mail)
|
||||||
* @param string Enable to return subscribed folders only
|
* @param string Enable to return subscribed folders only
|
||||||
|
* @param array Will be filled with folder-types data
|
||||||
*
|
*
|
||||||
* @return array List of folders
|
* @return array List of folders
|
||||||
*/
|
*/
|
||||||
public static function list_folders($root = '', $mbox = '*', $filter = null, $subscribed = false)
|
public static function list_folders($root = '', $mbox = '*', $filter = null, $subscribed = false, &$folderdata = array())
|
||||||
{
|
{
|
||||||
if (!self::setup()) {
|
if (!self::setup()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -412,14 +413,14 @@ class kolab_storage
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$regexp = '/^' . preg_quote($filter, '/') . '(\..+)?$/';
|
$folderdata = array_map('implode', $folderdata);
|
||||||
|
$regexp = '/^' . preg_quote($filter, '/') . '(\..+)?$/';
|
||||||
|
|
||||||
// In some conditions we can skip LIST command (?)
|
// In some conditions we can skip LIST command (?)
|
||||||
if ($subscribed == false && $filter != 'mail' && $prefix == '*') {
|
if ($subscribed == false && $filter != 'mail' && $prefix == '*') {
|
||||||
foreach ($folderdata as $idx => $folder) {
|
foreach ($folderdata as $folder => $type) {
|
||||||
$type = $folder[self::CTYPE_KEY];
|
|
||||||
if (!preg_match($regexp, $type)) {
|
if (!preg_match($regexp, $type)) {
|
||||||
unset($folderdata[$idx]);
|
unset($folderdata[$folder]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array_keys($folderdata);
|
return array_keys($folderdata);
|
||||||
|
@ -440,7 +441,7 @@ class kolab_storage
|
||||||
|
|
||||||
// Filter folders list
|
// Filter folders list
|
||||||
foreach ($folders as $idx => $folder) {
|
foreach ($folders as $idx => $folder) {
|
||||||
$type = !empty($folderdata[$folder]) ? $folderdata[$folder][self::CTYPE_KEY] : null;
|
$type = $folderdata[$folder];
|
||||||
|
|
||||||
if ($filter == 'mail' && empty($type)) {
|
if ($filter == 'mail' && empty($type)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -54,30 +54,34 @@ class kolab_storage_folder
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*/
|
*/
|
||||||
function __construct($name, $imap = null)
|
function __construct($name, $type = null)
|
||||||
{
|
{
|
||||||
$this->imap = is_object($imap) ? $imap : rcube::get_instance()->get_storage();
|
$this->imap = rcube::get_instance()->get_storage();
|
||||||
$this->imap->set_options(array('skip_deleted' => true));
|
$this->imap->set_options(array('skip_deleted' => true));
|
||||||
$this->cache = new kolab_storage_cache($this);
|
$this->cache = new kolab_storage_cache($this);
|
||||||
$this->set_folder($name);
|
$this->set_folder($name, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the IMAP folder name this instance connects to
|
* Set the IMAP folder this instance connects to
|
||||||
*
|
*
|
||||||
* @param string The folder name/path
|
* @param string The folder name/path
|
||||||
|
* @param string Optional folder type if known
|
||||||
*/
|
*/
|
||||||
public function set_folder($name)
|
public function set_folder($name, $type = null)
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
if (!$type) {
|
||||||
|
$metadata = $this->imap->get_metadata($name, array(kolab_storage::CTYPE_KEY));
|
||||||
|
$type = $metadata[$this->name][kolab_storage::CTYPE_KEY];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->name = $name;
|
||||||
|
$this->type_annotation = $type;
|
||||||
|
$this->type = reset(explode('.', $type));
|
||||||
|
$this->resource_uri = null;
|
||||||
|
|
||||||
$this->imap->set_folder($this->name);
|
$this->imap->set_folder($this->name);
|
||||||
|
|
||||||
$metadata = $this->imap->get_metadata($this->name, array(kolab_storage::CTYPE_KEY));
|
|
||||||
$this->type_annotation = $metadata[$this->name][kolab_storage::CTYPE_KEY];
|
|
||||||
$this->type = reset(explode('.', $this->type_annotation));
|
|
||||||
$this->resource_uri = null;
|
|
||||||
|
|
||||||
$this->cache->set_folder($this);
|
$this->cache->set_folder($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue