diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-04-25 23:38:04 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-04-25 23:38:04 +0000 |
commit | 10dbfea6f633107a90d84d07bba70e807d172eeb (patch) | |
tree | e2fbd06e6c20b923f75fc589e814e4bfafb79a8c /picture.php | |
parent | 94aa1b52822c599229db9933c4d5678484afe467 (diff) |
- less mysql queries on picture page (under some circumstances)
git-svn-id: http://piwigo.org/svn/trunk@2309 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | picture.php | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/picture.php b/picture.php index d6ce69ca0..286b51ff6 100644 --- a/picture.php +++ b/picture.php @@ -612,7 +612,7 @@ $template->assign( 'SHOW_PICTURE_NAME_ON_TITLE' => $conf['show_picture_name_on_title'], 'LEVEL_SEPARATOR' => $conf['level_separator'], - + 'FILE_PICTURE_NAV_BUTTONS' => 'picture_nav_buttons.tpl', 'U_HOME' => make_index_url(), @@ -637,7 +637,7 @@ if (is_admin()) ) ); } - + $template->assign( array( 'U_CADDIE' => add_url_params($url_self, @@ -815,15 +815,38 @@ if ( count($tags) ) } // 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->append( - 'related_categories', - count($related_categories) > 3 - ? get_cat_display_name_cache($category['uppercats']) - : get_cat_display_name_from_id($category['category_id']) + 'related_categories', + 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->append('related_categories', get_cat_display_name($cats) ); + } +} // maybe someone wants a special display (call it before page_header so that // they can add stylesheets) |