Changeset 2310 for branches


Ignore:
Timestamp:
Apr 26, 2008, 1:39:06 AM (17 years ago)
Author:
rvelices
Message:
  • merge r2308 and r2309 from trunk to branch-1_7
  • minor mysql query optimizations
  • less mysql queries on the picture page (under some circumstances)
Location:
branches/branch-1_7
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_7/include/functions.inc.php

    r2220 r2310  
    534534  }
    535535
    536   // here we ask the database the current date and time, and we extract
    537   // {year, month, day} from the current date. We could do this during the
    538   // insert query with a CURDATE(), CURTIME(), DATE_FORMAT(CURDATE(), '%Y')
    539   // ... but I (plg) think it would cost more than a double query and a PHP
    540   // extraction.
    541   $query = '
    542 SELECT CURDATE(), CURTIME()
    543 ;';
    544   list($curdate, $curtime) = mysql_fetch_row(pwg_query($query));
    545 
    546   list($curyear, $curmonth, $curday) = explode('-', $curdate);
    547   list($curhour) = explode(':', $curtime);
    548 
    549536  $query = '
    550537INSERT INTO '.HISTORY_TABLE.'
     
    566553  VALUES
    567554  (
    568     \''.$curdate.'\',
    569     \''.$curtime.'\',
    570     '.$curyear.',
    571     '.$curmonth.',
    572     '.$curday.',
    573     '.$curhour.',
     555    CURDATE(),
     556    CURTIME(),
     557    YEAR( CURDATE() ),
     558    MONTH( CURDATE() ),
     559    DAYOFMONTH( CURDATE() ),
     560    HOUR( CURTIME() ),
    574561    '.$user['id'].',
    575562    \''.$_SERVER['REMOTE_ADDR'].'\',
  • branches/branch-1_7/include/functions_tag.inc.php

    r1900 r2310  
    5454          'visible_images' => 'image_id'
    5555        ),
    56       'WHERE'
    57     );
     56      '
     57  WHERE'
     58    ).'
     59  GROUP BY tag_id
     60  ORDER BY NULL';
     61  $tag_counters = simple_hash_from_query($query, 'tag_id', 'counter');
    5862
    5963  if (!empty($where_tag_img))
     
    261265  ORDER BY counter DESC
    262266  LIMIT 0,'.$max_tags;
     267  }
     268  else
     269  {
     270    $query .= '
     271  ORDER BY NULL';
    263272  }
    264273
  • branches/branch-1_7/include/picture_rate.inc.php

    r2202 r2310  
    3333if ($conf['rate'])
    3434{
    35   $query = '
     35  if ( NULL != $picture['current']['average_rate'] )
     36  {
     37    $query = '
    3638SELECT COUNT(rate) AS count
    3739     , ROUND(AVG(rate),2) AS average
     
    4042  WHERE element_id = '.$picture['current']['id'].'
    4143;';
    42   $row = mysql_fetch_array(pwg_query($query));
     44    $row = mysql_fetch_array(pwg_query($query));
     45  }
     46  else
     47  { // avg rate null -> no rate -> no need to query db
     48    $row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL );
     49  }
     50
    4351  if ($row['count'] == 0)
    4452  {
  • branches/branch-1_7/picture.php

    r2203 r2310  
    771771$template->assign_vars($infos);
    772772
     773
    773774// related categories
    774 foreach ($related_categories as $category)
    775 {
     775if ( count($related_categories)==1 and
     776    isset($page['category']) and
     777    $related_categories[0]['category_id']==$page['category']['id'] )
     778{ // no need to go to db, we have all the info
    776779  $template->assign_block_vars(
    777     'category',
    778     array(
    779       'LINE' => count($related_categories) > 3
    780         ? get_cat_display_name_cache($category['uppercats'])
    781         : get_cat_display_name_from_id($category['category_id'])
    782       )
    783     );
     780      'category',
     781      array('LINE'=>get_cat_display_name( $page['category']['upper_names'] ))
     782    );
     783}
     784else
     785{ // use only 1 sql query to get names for all related categories
     786  $ids = array();
     787  foreach ($related_categories as $category)
     788  {// add all uppercats to $ids
     789    $ids = array_merge($ids, explode(',', $category['uppercats']) );
     790  }
     791  $ids = array_unique($ids);
     792  $query = '
     793SELECT id, name, permalink
     794  FROM '.CATEGORIES_TABLE.'
     795  WHERE id IN ('.implode(',',$ids).')';
     796  $cat_map = hash_from_query($query, 'id');
     797  foreach ($related_categories as $category)
     798  {
     799    $cats = array();
     800    foreach ( explode(',', $category['uppercats']) as $id )
     801    {
     802      $cats[] = $cat_map[$id];
     803    }
     804    $template->assign_block_vars('category', array('LINE'=>get_cat_display_name($cats) ) );
     805  }
    784806}
    785807
Note: See TracChangeset for help on using the changeset viewer.