Performance: Limit number of SQL queries needed for "object relations update" operation

This commit is contained in:
Aleksander Machniak 2016-02-13 13:09:59 +01:00
parent 52053f355a
commit 446cd0dfe1
4 changed files with 18 additions and 30 deletions

View file

@ -572,14 +572,8 @@ class kolab_calendar extends kolab_storage_folder_api
*/
protected function save_links($uid, $links)
{
// make sure we have a valid array
if (empty($links)) {
$links = array();
}
$storage = kolab_storage_config::get_instance();
$remove = array_diff($storage->get_object_links($uid), $links);
return $storage->save_object_links($uid, $links, $remove);
return $storage->save_object_links($uid, (array) $links);
}
/**

View file

@ -1247,12 +1247,8 @@ class kolab_notes extends rcube_plugin
private function save_links($uid, $links)
{
if (empty($links)) {
$links = array();
}
$config = kolab_storage_config::get_instance();
$remove = array_diff($config->get_object_links($uid), $links);
return $config->save_object_links($uid, $links, $remove);
return $config->save_object_links($uid, (array) $links);
}
/**

View file

@ -711,7 +711,8 @@ class kolab_storage_config
* Find objects linked with the given groupware object through a relation
*
* @param string Object UUID
* @param array List of related URIs
*
* @return array List of related URIs
*/
public function get_object_links($uid)
{
@ -735,27 +736,30 @@ class kolab_storage_config
}
/**
* Save relations of an object.
* Note, that we already support only one-to-one relations.
* So, all relations to the object that are not provided in $links
* argument will be removed.
*
* @param string $uid Object UUID
* @param array $links List of related-object URIs
*
* @return bool True on success, False on failure
*/
public function save_object_links($uid, $links, $remove = array())
public function save_object_links($uid, $links)
{
$object_uri = self::build_member_url($uid);
$relations = $this->get_relations_for_member($uid);
$done = false;
$relations = $this->get_relations_for_member($uid);
$done = false;
foreach ($relations as $relation) {
// make relation members up-to-date
kolab_storage_config::resolve_members($relation);
// remove and add links
$members = array_diff($relation['members'], (array)$remove);
$members = array($object_uri);
$members = array_unique(array_merge($members, $links));
// make sure the object_uri is still a member
if (!in_array($object_uri, $members)) {
$members[$object_uri];
}
// remove relation if no other members remain
if (count($members) <= 1) {
$done = $this->delete($relation['uid']);
@ -768,7 +772,7 @@ class kolab_storage_config
}
// no changes, we're happy
else {
$done = true;
$done = true;
$links = array();
}
}

View file

@ -1114,14 +1114,8 @@ class tasklist_kolab_driver extends tasklist_driver
*/
private function save_links($uid, $links)
{
// make sure we have a valid array
if (empty($links)) {
$links = array();
}
$config = kolab_storage_config::get_instance();
$remove = array_diff($config->get_object_links($uid), $links);
return $config->save_object_links($uid, $links, $remove);
return $config->save_object_links($uid, (array) $links);
}
/**