Permalink
Browse files

fixes #972 use an alternative algorithm to discover number of future …

…orphans, with very large albums
  • Loading branch information...
plegall committed Jan 28, 2019
1 parent b8d6f01 commit b29ab344e9d727f483613f244d11e8971cb03df1
Showing with 36 additions and 5 deletions.
  1. +36 −5 admin/cat_modify.php
@@ -218,18 +218,49 @@ function get_site_url($category_id)
if ($category['nb_images_recursive'] > 0)
{
$query = '
// if we don't have "too many" photos, it's faster to compute the orphans with MySQL
if ($category['nb_images_recursive'] < 30000)
{
$query = '
SELECT
DISTINCT(image_id)
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id NOT IN ('.implode(',', $subcat_ids).')
AND image_id IN ('.implode(',', $image_ids_recursive).')
;';
$image_ids_associated_outside = query2array($query, null, 'image_id');
$category['nb_images_associated_outside'] = count($image_ids_associated_outside);
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_associated_outside);
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
$image_ids_associated_outside = query2array($query, null, 'image_id');
$category['nb_images_associated_outside'] = count($image_ids_associated_outside);
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_associated_outside);
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
}
// else it's better to avoid sending a huge SQL request, we compute the orphan list with PHP
else
{
$image_ids_recursive_keys = array_flip($image_ids_recursive);
$query = '
SELECT
image_id
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id NOT IN ('.implode(',', $subcat_ids).')
;';
$image_ids_associated_outside = query2array($query, null, 'image_id');
$image_ids_not_orphan = array();
foreach ($image_ids_associated_outside as $image_id)
{
if (isset($image_ids_recursive_keys[$image_id]))
{
$image_ids_not_orphan[] = $image_id;
}
}
$category['nb_images_associated_outside'] = count(array_unique($image_ids_not_orphan));
$image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_not_orphan);
$category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan);
}
}
// Navigation path

0 comments on commit b29ab34

Please sign in to comment.