From 1d9bb50cbdc0b6f54ef340f92ede0556d74a5a97 Mon Sep 17 00:00:00 2001 From: rvelices Date: Wed, 15 Jan 2014 20:38:44 +0000 Subject: change stupid sql query (no join at all instead of a triple join) git-svn-id: http://piwigo.org/svn/trunk@26761 68402e56-0260-453c-a942-63ccdbb3a9ee --- comments.php | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'comments.php') diff --git a/comments.php b/comments.php index 9dcab6a33..a41e0c57a 100644 --- a/comments.php +++ b/comments.php @@ -383,6 +383,7 @@ $category_ids = array(); $query = ' SELECT SQL_CALC_FOUND_ROWS com.id AS comment_id, com.image_id, + ic.category_id, com.author, com.author_id, u.'.$conf['user_fields']['email'].' AS user_email, @@ -412,6 +413,7 @@ while ($row = pwg_db_fetch_assoc($result)) { $comments[] = $row; $element_ids[] = $row['image_id']; + $category_ids[] = $row['category_id']; } list($counter) = pwg_db_fetch_row(pwg_query('SELECT FOUND_ROWS()')); @@ -430,37 +432,18 @@ $template->assign('navbar', $navbar); if (count($comments) > 0) { // retrieving element informations - $elements = array(); $query = ' SELECT * FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $element_ids).') ;'; - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $elements[$row['id']] = $row; - } + $elements = hash_from_query($query, 'id'); // retrieving category informations - $query = ' -SELECT c.id, name, permalink, uppercats, com.id as comment_id - FROM '.CATEGORIES_TABLE.' AS c - LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic - ON c.id=ic.category_id - LEFT JOIN '.COMMENTS_TABLE.' AS com - ON ic.image_id=com.image_id - '.get_sql_condition_FandF - ( - array - ( - 'forbidden_categories' => 'c.id', - 'visible_categories' => 'c.id' - ), - 'WHERE' - ).' -;'; - $categories = hash_from_query($query, 'comment_id'); + $query = 'SELECT id, name, permalink, uppercats + FROM '.CATEGORIES_TABLE.' + WHERE id IN ('.implode(',', $category_ids).')'; + $categories = hash_from_query($query, 'id'); foreach ($comments as $comment) { @@ -479,7 +462,7 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id // link to the full size picture $url = make_picture_url( array( - 'category' => $categories[ $comment['comment_id'] ], + 'category' => $categories[ $comment['category_id'] ], 'image_id' => $comment['image_id'], 'image_file' => $elements[$comment['image_id']]['file'], ) -- cgit v1.2.3