From 8c4b3fb7db2b8daeec53afad001d7c62d2f97077 Mon Sep 17 00:00:00 2001 From: plegall Date: Fri, 2 Aug 2024 17:47:45 +0200 Subject: [PATCH] fixes #2198 smarter way to deal with filesize bounds --- admin/batch_manager.php | 10 ++++------ include/functions_search.inc.php | 4 +++- index.php | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/admin/batch_manager.php b/admin/batch_manager.php index 171592eb5..de50e3e9b 100644 --- a/admin/batch_manager.php +++ b/admin/batch_manager.php @@ -571,12 +571,14 @@ if (isset($_SESSION['bulk_manager_filter']['filesize'])) if (isset($_SESSION['bulk_manager_filter']['filesize']['min'])) { - $where_clause[] = 'filesize >= '.$_SESSION['bulk_manager_filter']['filesize']['min']*1024; + // to counter the effect of converting kB to mB and rounding, we need to go slightly lower for the minimum value + $where_clause[] = 'filesize >= '.($_SESSION['bulk_manager_filter']['filesize']['min'] - 0.1)*1024; } if (isset($_SESSION['bulk_manager_filter']['filesize']['max'])) { - $where_clause[] = 'filesize <= '.$_SESSION['bulk_manager_filter']['filesize']['max']*1024; + // to counter the effect of converting kB to mB and rounding, we need to go slightly higher for the maximum value + $where_clause[] = 'filesize <= '.($_SESSION['bulk_manager_filter']['filesize']['max'] + 0.1)*1024; } $query = ' @@ -785,10 +787,6 @@ if (empty($filesizes)) $filesizes = array_unique($filesizes); sort($filesizes); -// add 0.1MB to the last value, to make sure the heavier photo will be in -// the result -$filesizes[count($filesizes)-1]+= 0.1; - $filesize['list'] = implode(',', $filesizes); $filesize['bounds'] = array( diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 476363f72..79cc276e9 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -416,7 +416,9 @@ SELECT if (!empty($search['fields']['filesize_min']) && !empty($search['fields']['filesize_max'])) { - $clauses[] = 'filesize BETWEEN '.$search['fields']['filesize_min'].' AND '.$search['fields']['filesize_max']; + // because of conversion from kB to mB, approximation, then conversion back to kB, + // we need to slightly enlarge the range for search + $clauses[] = 'filesize BETWEEN '.($search['fields']['filesize_min']-100).' AND '.($search['fields']['filesize_max']+100); } if (!empty($search['fields']['height_min']) && !empty($search['fields']['height_max'])) diff --git a/index.php b/index.php index ae5ee3a36..28df96d43 100644 --- a/index.php +++ b/index.php @@ -532,10 +532,6 @@ SELECT $filesizes = array_unique($filesizes); sort($filesizes); - // add 0.1MB to the last value, to make sure the heaviest photo will be in - // the result - $filesizes[count($filesizes)-1]+= 0.1; - $filesize['list'] = implode(',', $filesizes); $filesize['bounds'] = array( @@ -543,6 +539,9 @@ SELECT 'max' => sprintf('%.2f',end($filesizes)), ); + // warning: we will (hopefully) have smarter values for filters. The min/max of the + // current search won't always be the first/last values found. It's going to be a + // problem with this way to select selected values $filesize['selected'] = array( 'min' => !empty($my_search['fields']['filesize_min']) ? sprintf('%.2f', $my_search['fields']['filesize_min']/1024) : sprintf('%.2f',$filesizes[0]), 'max' => !empty($my_search['fields']['filesize_max']) ? sprintf('%.2f', $my_search['fields']['filesize_max']/1024) : sprintf('%.2f',end($filesizes)),