Changeset 2309 for trunk/picture.php


Ignore:
Timestamp:
Apr 26, 2008, 1:38:04 AM (16 years ago)
Author:
rvelices
Message:
  • less mysql queries on picture page (under some circumstances)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/picture.php

    r2299 r2309  
    613613
    614614    'LEVEL_SEPARATOR' => $conf['level_separator'],
    615    
     615
    616616    'FILE_PICTURE_NAV_BUTTONS' => 'picture_nav_buttons.tpl',
    617617
     
    638638      );
    639639  }
    640  
     640
    641641  $template->assign(
    642642    array(
     
    816816
    817817// related categories
    818 foreach ($related_categories as $category)
    819 {
     818if ( count($related_categories)==1 and
     819    isset($page['category']) and
     820    $related_categories[0]['category_id']==$page['category']['id'] )
     821{ // no need to go to db, we have all the info
    820822  $template->append(
    821     'related_categories',
    822       count($related_categories) > 3
    823         ? get_cat_display_name_cache($category['uppercats'])
    824         : get_cat_display_name_from_id($category['category_id'])
    825     );
     823      'related_categories',
     824      get_cat_display_name( $page['category']['upper_names'] )
     825    );
     826}
     827else
     828{ // use only 1 sql query to get names for all related categories
     829  $ids = array();
     830  foreach ($related_categories as $category)
     831  {// add all uppercats to $ids
     832    $ids = array_merge($ids, explode(',', $category['uppercats']) );
     833  }
     834  $ids = array_unique($ids);
     835  $query = '
     836SELECT id, name, permalink
     837  FROM '.CATEGORIES_TABLE.'
     838  WHERE id IN ('.implode(',',$ids).')';
     839  $cat_map = hash_from_query($query, 'id');
     840  foreach ($related_categories as $category)
     841  {
     842    $cats = array();
     843    foreach ( explode(',', $category['uppercats']) as $id )
     844    {
     845      $cats[] = $cat_map[$id];
     846    }
     847    $template->append('related_categories', get_cat_display_name($cats) );
     848  }
    826849}
    827850
Note: See TracChangeset for help on using the changeset viewer.