mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
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
This commit is contained in:
33
comments.php
33
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'],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user