aboutsummaryrefslogtreecommitdiffstats
path: root/picture.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2008-04-25 23:39:06 +0000
committerrvelices <rv-github@modusoptimus.com>2008-04-25 23:39:06 +0000
commitf95f48a226118dd541130e2cec8e18fd13bff128 (patch)
treed65014464efe3e2f0ca9f83156914797a337813b /picture.php
parentcd30335df7f2a4c3b15c5f2ba181dc1b0444f00a (diff)
- merge r2308 and r2309 from trunk to branch-1_7
- minor mysql query optimizations - less mysql queries on the picture page (under some circumstances) git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2310 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'picture.php')
-rw-r--r--picture.php38
1 files changed, 30 insertions, 8 deletions
diff --git a/picture.php b/picture.php
index c933f07df..0e64d2946 100644
--- a/picture.php
+++ b/picture.php
@@ -770,18 +770,40 @@ else
$template->assign_vars($infos);
+
// related categories
-foreach ($related_categories as $category)
-{
+if ( count($related_categories)==1 and
+ isset($page['category']) and
+ $related_categories[0]['category_id']==$page['category']['id'] )
+{ // no need to go to db, we have all the info
$template->assign_block_vars(
- 'category',
- array(
- 'LINE' => count($related_categories) > 3
- ? get_cat_display_name_cache($category['uppercats'])
- : get_cat_display_name_from_id($category['category_id'])
- )
+ 'category',
+ array('LINE'=>get_cat_display_name( $page['category']['upper_names'] ))
);
}
+else
+{ // use only 1 sql query to get names for all related categories
+ $ids = array();
+ foreach ($related_categories as $category)
+ {// add all uppercats to $ids
+ $ids = array_merge($ids, explode(',', $category['uppercats']) );
+ }
+ $ids = array_unique($ids);
+ $query = '
+SELECT id, name, permalink
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id IN ('.implode(',',$ids).')';
+ $cat_map = hash_from_query($query, 'id');
+ foreach ($related_categories as $category)
+ {
+ $cats = array();
+ foreach ( explode(',', $category['uppercats']) as $id )
+ {
+ $cats[] = $cat_map[$id];
+ }
+ $template->assign_block_vars('category', array('LINE'=>get_cat_display_name($cats) ) );
+ }
+}
//slideshow end
if (isset($_GET['slideshow']))