- less mysql queries on picture page (under some circumstances)
git-svn-id: http://piwigo.org/svn/trunk@2309 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
94aa1b5282
commit
10dbfea6f6
2 changed files with 40 additions and 10 deletions
|
|
@ -27,6 +27,8 @@
|
|||
*/
|
||||
|
||||
if ($conf['rate'])
|
||||
{
|
||||
if ( NULL != $picture['current']['average_rate'] )
|
||||
{
|
||||
$query = '
|
||||
SELECT COUNT(rate) AS count
|
||||
|
|
@ -36,6 +38,11 @@ SELECT COUNT(rate) AS count
|
|||
WHERE element_id = '.$picture['current']['id'].'
|
||||
;';
|
||||
$row = mysql_fetch_array(pwg_query($query));
|
||||
}
|
||||
else
|
||||
{ // avg rate null -> no rate -> no need to query db
|
||||
$row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL );
|
||||
}
|
||||
$template->assign('rate_summary', $row);
|
||||
|
||||
$user_rate = null;
|
||||
|
|
|
|||
33
picture.php
33
picture.php
|
|
@ -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'])
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue