Changeset 26761


Ignore:
Timestamp:
Jan 15, 2014, 9:38:44 PM (7 years ago)
Author:
rvelices
Message:

change stupid sql query (no join at all instead of a triple join)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/comments.php

    r26759 r26761  
    384384SELECT SQL_CALC_FOUND_ROWS com.id AS comment_id,
    385385       com.image_id,
     386       ic.category_id,
    386387       com.author,
    387388       com.author_id,
     
    413414  $comments[] = $row;
    414415  $element_ids[] = $row['image_id'];
     416  $category_ids[] = $row['category_id'];
    415417}
    416418list($counter) = pwg_db_fetch_row(pwg_query('SELECT FOUND_ROWS()'));
     
    431433{
    432434  // retrieving element informations
    433   $elements = array();
    434435  $query = '
    435436SELECT *
     
    437438  WHERE id IN ('.implode(',', $element_ids).')
    438439;';
    439   $result = pwg_query($query);
    440   while ($row = pwg_db_fetch_assoc($result))
    441   {
    442     $elements[$row['id']] = $row;
    443   }
     440  $elements = hash_from_query($query, 'id');
    444441
    445442  // retrieving category informations
    446   $query = '
    447 SELECT c.id, name, permalink, uppercats, com.id as comment_id
    448   FROM '.CATEGORIES_TABLE.' AS c
    449   LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
    450   ON c.id=ic.category_id
    451   LEFT JOIN '.COMMENTS_TABLE.' AS com
    452   ON ic.image_id=com.image_id
    453   '.get_sql_condition_FandF
    454     (
    455       array
    456       (
    457         'forbidden_categories' => 'c.id',
    458         'visible_categories' => 'c.id'
    459        ),
    460       'WHERE'
    461      ).'
    462 ;';
    463   $categories = hash_from_query($query, 'comment_id');
     443  $query = 'SELECT id, name, permalink, uppercats
     444  FROM '.CATEGORIES_TABLE.'
     445  WHERE id IN ('.implode(',', $category_ids).')';
     446  $categories = hash_from_query($query, 'id');
    464447
    465448  foreach ($comments as $comment)
     
    480463    $url = make_picture_url(
    481464      array(
    482         'category' => $categories[ $comment['comment_id'] ],
     465        'category' => $categories[ $comment['category_id'] ],
    483466        'image_id' => $comment['image_id'],
    484467        'image_file' => $elements[$comment['image_id']]['file'],
Note: See TracChangeset for help on using the changeset viewer.