mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 03:09:58 +03:00
fixes #1982 only fetch the list of albums we want to display
... not the full list. Makes huge difference when you have thousands of albums at the same level.
This commit is contained in:
parent
eb0759ef12
commit
445cc4ec14
1 changed files with 31 additions and 12 deletions
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
|
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
|
||||||
$query = '
|
$query = '
|
||||||
SELECT
|
SELECT SQL_CALC_FOUND_ROWS
|
||||||
c.*,
|
c.*,
|
||||||
user_representative_picture_id,
|
user_representative_picture_id,
|
||||||
nb_images,
|
nb_images,
|
||||||
|
@ -27,17 +27,19 @@ SELECT
|
||||||
FROM '.CATEGORIES_TABLE.' c
|
FROM '.CATEGORIES_TABLE.' c
|
||||||
INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ucc
|
INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ucc
|
||||||
ON id = cat_id
|
ON id = cat_id
|
||||||
AND user_id = '.$user['id'];
|
AND user_id = '.$user['id'].'
|
||||||
|
WHERE count_images > 0
|
||||||
|
';
|
||||||
|
|
||||||
if ('recent_cats' == $page['section'])
|
if ('recent_cats' == $page['section'])
|
||||||
{
|
{
|
||||||
$query.= '
|
$query.= '
|
||||||
WHERE '.get_recent_photos_sql('date_last');
|
AND '.get_recent_photos_sql('date_last');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$query.= '
|
$query.= '
|
||||||
WHERE id_uppercat '.(!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']);
|
AND id_uppercat '.(!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query.= '
|
$query.= '
|
||||||
|
@ -46,13 +48,26 @@ $query.= '
|
||||||
'AND'
|
'AND'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// special string to let plugins modify this query at this exact position
|
||||||
|
$query.= '
|
||||||
|
-- after conditions
|
||||||
|
';
|
||||||
|
|
||||||
if ('recent_cats' != $page['section'])
|
if ('recent_cats' != $page['section'])
|
||||||
{
|
{
|
||||||
$query.= '
|
$query.= '
|
||||||
ORDER BY `rank`';
|
ORDER BY `rank`';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$query.= '
|
||||||
|
LIMIT '.$conf['nb_categories_page'].' OFFSET '.($page['startcat'] ?? 0).'
|
||||||
|
;';
|
||||||
|
|
||||||
|
$query = trigger_change('loc_begin_index_category_thumbnails_query', $query);
|
||||||
|
|
||||||
$result = pwg_query($query);
|
$result = pwg_query($query);
|
||||||
|
list($page['total_categories']) = pwg_db_fetch_row(pwg_query('SELECT FOUND_ROWS()'));
|
||||||
|
|
||||||
$categories = array();
|
$categories = array();
|
||||||
$category_ids = array();
|
$category_ids = array();
|
||||||
$image_ids = array();
|
$image_ids = array();
|
||||||
|
@ -74,7 +89,7 @@ while ($row = pwg_db_fetch_assoc($result))
|
||||||
{ // searching a random representant among elements in sub-categories
|
{ // searching a random representant among elements in sub-categories
|
||||||
$image_id = get_random_image_in_category($row);
|
$image_id = get_random_image_in_category($row);
|
||||||
}
|
}
|
||||||
elseif ($row['count_categories']>0 and $row['count_images']>0)
|
elseif ($row['count_categories']>0 and $row['count_images']>0) // at this point, $row['count_images'] should always be >0 (used as condition in SQL)
|
||||||
{ // searching a random representant among representant of sub-categories
|
{ // searching a random representant among representant of sub-categories
|
||||||
$query = '
|
$query = '
|
||||||
SELECT representative_picture_id
|
SELECT representative_picture_id
|
||||||
|
@ -113,6 +128,16 @@ SELECT representative_picture_id
|
||||||
$categories[] = $row;
|
$categories[] = $row;
|
||||||
$category_ids[] = $row['id'];
|
$category_ids[] = $row['id'];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$logger->info(
|
||||||
|
sprintf(
|
||||||
|
'[%s] category #%u was listed in SQL but no image_id found, so it was skipped',
|
||||||
|
basename(__FILE__),
|
||||||
|
$row['id']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
unset($image_id);
|
unset($image_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,13 +355,7 @@ if (count($categories) > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pagination
|
// pagination
|
||||||
$page['total_categories'] = count($tpl_thumbnails_var);
|
$tpl_thumbnails_var_selection = $tpl_thumbnails_var;
|
||||||
|
|
||||||
$tpl_thumbnails_var_selection = array_slice(
|
|
||||||
$tpl_thumbnails_var,
|
|
||||||
$page['startcat'],
|
|
||||||
$conf['nb_categories_page']
|
|
||||||
);
|
|
||||||
|
|
||||||
$derivative_params = trigger_change('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_THUMB) );
|
$derivative_params = trigger_change('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_THUMB) );
|
||||||
$tpl_thumbnails_var_selection = trigger_change('loc_end_index_category_thumbnails', $tpl_thumbnails_var_selection);
|
$tpl_thumbnails_var_selection = trigger_change('loc_end_index_category_thumbnails', $tpl_thumbnails_var_selection);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue