From 236142143e1ccb65c62cbbd98e5198a6c670418a Mon Sep 17 00:00:00 2001 From: rvelices Date: Wed, 15 Jan 2014 20:00:38 +0000 Subject: one less expensive query in comments.php (triple table join is already being done and we can use the result) git-svn-id: http://piwigo.org/svn/trunk@26759 68402e56-0260-453c-a942-63ccdbb3a9ee --- comments.php | 46 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) (limited to 'comments.php') diff --git a/comments.php b/comments.php index 945ea8f8a..9dcab6a33 100644 --- a/comments.php +++ b/comments.php @@ -372,29 +372,6 @@ else $start = 0; } -$query = ' -SELECT COUNT(DISTINCT(com.id)) - FROM '.IMAGE_CATEGORY_TABLE.' AS ic - INNER JOIN '.COMMENTS_TABLE.' AS com - ON ic.image_id = com.image_id - LEFT JOIN '.USERS_TABLE.' As u - ON u.'.$conf['user_fields']['id'].' = com.author_id - WHERE '.implode(' - AND ', $page['where_clauses']).' -;'; -list($counter) = pwg_db_fetch_row(pwg_query($query)); - -$url = PHPWG_ROOT_PATH.'comments.php' - .get_query_string_diff(array('start','edit','delete','validate','pwg_token')); - -$navbar = create_navigation_bar($url, - $counter, - $start, - $page['items_number'], - ''); - -$template->assign('navbar', $navbar); - // +-----------------------------------------------------------------------+ // | last comments display | // +-----------------------------------------------------------------------+ @@ -404,7 +381,7 @@ $element_ids = array(); $category_ids = array(); $query = ' -SELECT com.id AS comment_id, +SELECT SQL_CALC_FOUND_ROWS com.id AS comment_id, com.image_id, com.author, com.author_id, @@ -421,13 +398,7 @@ SELECT com.id AS comment_id, ON u.'.$conf['user_fields']['id'].' = com.author_id WHERE '.implode(' AND ', $page['where_clauses']).' - GROUP BY comment_id, - com.image_id, - com.author, - com.author_id, - com.date, - com.content, - com.validated + GROUP BY comment_id ORDER BY '.$page['sort_by'].' '.$page['sort_order']; if ('all' != $page['items_number']) { @@ -442,6 +413,19 @@ while ($row = pwg_db_fetch_assoc($result)) $comments[] = $row; $element_ids[] = $row['image_id']; } +list($counter) = pwg_db_fetch_row(pwg_query('SELECT FOUND_ROWS()')); + +$url = PHPWG_ROOT_PATH.'comments.php' + .get_query_string_diff(array('start','edit','delete','validate','pwg_token')); + +$navbar = create_navigation_bar($url, + $counter, + $start, + $page['items_number'], + ''); + +$template->assign('navbar', $navbar); + if (count($comments) > 0) { -- cgit v1.2.3