From 0f2eceefb8a11ef18094e2ddcce6f5eea33d96fe Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 4 Mar 2010 17:07:10 +0000 Subject: [PATCH] Preseed link title-cache for link-list and link-string widget (Performance improvment, as all titles of an application get queried in a single query and NOT once for every link) --- etemplate/inc/class.link_widget.inc.php | 4 ++-- phpgwapi/inc/class.egw_link.inc.php | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/etemplate/inc/class.link_widget.inc.php b/etemplate/inc/class.link_widget.inc.php index 9595f705b4..a8798b4ccf 100644 --- a/etemplate/inc/class.link_widget.inc.php +++ b/etemplate/inc/class.link_widget.inc.php @@ -195,7 +195,7 @@ class link_widget } if ($value['to_id'] && $value['to_app']) { - $value = egw_link::get_links($value['to_app'],$value['to_id'],$only_app = $value['only_app']); + $value = egw_link::get_links($value['to_app'],$value['to_id'],$only_app = $value['only_app'],'link_lastmod DESC',true); if ($only_app) { foreach($value as $key => $id) @@ -287,7 +287,7 @@ class link_widget { $value['title'] = egw_link::title($app,$id); } - $links = egw_link::get_links($app,$id); + $links = egw_link::get_links($app,$id,'','link_lastmod DESC',true); $value['anz_links'] = count($links); $extension_data = $value; diff --git a/phpgwapi/inc/class.egw_link.inc.php b/phpgwapi/inc/class.egw_link.inc.php index f86f1cc3de..846f1713b9 100644 --- a/phpgwapi/inc/class.egw_link.inc.php +++ b/phpgwapi/inc/class.egw_link.inc.php @@ -56,6 +56,11 @@ * 'file_access' => 'app.class.method', // method to be called to check file access rights, see links_stream_wrapper class * // boolean file_access(string $id,int $check,string $rel_path) * 'find_extra' => array('name_preg' => '/^(?!.picture.jpg)$/') // extra options to egw_vfs::find, to eg. remove some files from the list of attachments + * 'edit' => array( + * 'menuaction' => 'app.class.method', + * ), + * 'edit_id' => 'app_id', + * 'edit_popup' => '400x300', * } * All entries are optional, thought you only get conected functionality, if you implement them ... * @@ -283,9 +288,10 @@ class egw_link extends solink * @param string/array $id id of entry in $app or array of links if entry not yet created * @param string $only_app if set return only links from $only_app (eg. only addressbook-entries) or NOT from if $only_app[0]=='!' * @param string $order='link_lastmod DESC' defaults to newest links first + * @param boolean $cache_titles=false should all titles be queryed and cached (allows to query each link app only once!) * @return array of links or empty array if no matching links found */ - static function get_links( $app,$id,$only_app='',$order='link_lastmod DESC' ) + static function get_links( $app,$id,$only_app='',$order='link_lastmod DESC',$cache_titles=false ) { if (self::DEBUG) echo "

egw_link::get_links(app='$app',id='$id',only_app='$only_app',order='$order')

\n"; @@ -319,7 +325,21 @@ class egw_link extends solink } } //echo "ids=
"; print_r($ids); echo "
\n"; + if ($cache_titles) + { + // agregate links by app + $app_ids = array(); + foreach($ids as $link) + { + $app_ids[$link['app']][] = $link['id']; + } + reset($ids); + foreach($app_ids as $appname => $a_ids) + { + self::titles($appname,array_unique($a_ids)); + } + } return $ids; }