From c456e66ef6fd8d11390181a40c66910ae01fbf4c Mon Sep 17 00:00:00 2001 From: lachlan Date: Fri, 20 Jan 2023 09:58:23 +1000 Subject: [PATCH] cast to into for search limit searches --- src/Module/Statistics/Stats.php | 6 +++--- src/Repository/Model/Search.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Module/Statistics/Stats.php b/src/Module/Statistics/Stats.php index d152c3d669..c0ec0acd5f 100644 --- a/src/Module/Statistics/Stats.php +++ b/src/Module/Statistics/Stats.php @@ -801,13 +801,13 @@ public static function get_recent($input_type, $count = 0, $offset = 0, $newest * get_user * This gets all stats for a type based on user with thresholds and all * If full is passed, doesn't limit based on date - * @param string $input_count + * @param string $count * @param string $input_type * @param integer $user * @param integer $full * @return array */ - public static function get_user($input_count, $input_type, $user, $full = 0) + public static function get_user($count, $input_type, $user, $full = 0) { $type = self::validate_type($input_type); @@ -816,7 +816,7 @@ public static function get_user($input_count, $input_type, $user, $full = 0) // Select Objects based on user // FIXME:: Requires table scan, look at improving - $sql = "SELECT `object_id`, COUNT(`id`) AS `count` FROM `object_count` WHERE `object_type` = ? AND `date` >= ? AND `user` = ? GROUP BY `object_id` ORDER BY `count` DESC LIMIT $input_count"; + $sql = "SELECT `object_id`, COUNT(`id`) AS `count` FROM `object_count` WHERE `object_type` = ? AND `date` >= ? AND `user` = ? GROUP BY `object_id` ORDER BY `count` DESC LIMIT " . (int)$count; $db_results = Dba::read($sql, array($type, $date, $user)); $results = array(); diff --git a/src/Repository/Model/Search.php b/src/Repository/Model/Search.php index 21aae2bc4d..900b89badd 100755 --- a/src/Repository/Model/Search.php +++ b/src/Repository/Model/Search.php @@ -1937,7 +1937,7 @@ private function _get_sql_album() case 'recent_added': $key = md5($input . $sql_match_operator); $where[] = "`addition_time_$key`.`id` IS NOT NULL"; - $table['addition_' . $key] = "LEFT JOIN (SELECT `id` FROM `album` ORDER BY $sql_match_operator DESC LIMIT $input) AS `addition_time_$key` ON `album`.`id` = `addition_time_$key`.`id`"; + $table['addition_' . $key] = "LEFT JOIN (SELECT `id` FROM `album` ORDER BY $sql_match_operator DESC LIMIT " . (int)$input . ") AS `addition_time_$key` ON `album`.`id` = `addition_time_$key`.`id`"; break; case 'genre': $where[] = "`album`.`id` IN (SELECT `tag_map`.`object_id` FROM `tag_map` LEFT JOIN `tag` ON `tag_map`.`tag_id` = `tag`.`id` AND `tag`.`is_hidden` = 0 AND `tag`.`name` $sql_match_operator ? WHERE `tag_map`.`object_type`='album' AND `tag`.`id` IS NOT NULL)"; @@ -2400,7 +2400,7 @@ private function _get_sql_artist() case 'recent_played': $key = md5($input . $sql_match_operator); $where[] = "`played_$key`.`object_id` IS NOT NULL"; - $table['played_' . $key] = "LEFT JOIN (SELECT `object_id` FROM `object_count` WHERE `object_type` = 'artist' ORDER BY $sql_match_operator DESC LIMIT $input) AS `played_$key` ON `artist`.`id` = `played_$key`.`object_id`"; + $table['played_' . $key] = "LEFT JOIN (SELECT `object_id` FROM `object_count` WHERE `object_type` = 'artist' ORDER BY $sql_match_operator DESC LIMIT " . (int)$input . ") AS `played_$key` ON `artist`.`id` = `played_$key`.`object_id`"; break; case 'catalog': $where[] = "`catalog_se`.`id` $sql_match_operator ?"; @@ -2875,17 +2875,17 @@ private function _get_sql_song() case 'recent_played': $key = md5($input . $sql_match_operator); $where[] = "`played_$key`.`object_id` IS NOT NULL"; - $table['played_' . $key] = "LEFT JOIN (SELECT `object_id` FROM `object_count` WHERE `object_type` = 'song' ORDER BY $sql_match_operator DESC LIMIT $input) AS `played_$key` ON `song`.`id` = `played_$key`.`object_id`"; + $table['played_' . $key] = "LEFT JOIN (SELECT `object_id` FROM `object_count` WHERE `object_type` = 'song' ORDER BY $sql_match_operator DESC LIMIT " . (int)$input . ") AS `played_$key` ON `song`.`id` = `played_$key`.`object_id`"; break; case 'recent_added': $key = md5($input . $sql_match_operator); $where[] = "`addition_time_$key`.`id` IS NOT NULL"; - $table['addition_' . $key] = "LEFT JOIN (SELECT `id` FROM `song` ORDER BY $sql_match_operator DESC LIMIT $input) AS `addition_time_$key` ON `song`.`id` = `addition_time_$key`.`id`"; + $table['addition_' . $key] = "LEFT JOIN (SELECT `id` FROM `song` ORDER BY $sql_match_operator DESC LIMIT " . (int)$input . ") AS `addition_time_$key` ON `song`.`id` = `addition_time_$key`.`id`"; break; case 'recent_updated': $key = md5($input . $sql_match_operator); $where[] = "`update_time_$key`.`id` IS NOT NULL"; - $table['update_' . $key] = "LEFT JOIN (SELECT `id` FROM `song` ORDER BY $sql_match_operator DESC LIMIT $input) AS `update_time_$key` ON `song`.`id` = `update_time_$key`.`id`"; + $table['update_' . $key] = "LEFT JOIN (SELECT `id` FROM `song` ORDER BY $sql_match_operator DESC LIMIT " . (int)$input . ") AS `update_time_$key` ON `song`.`id` = `update_time_$key`.`id`"; break; case 'mbid': if (!$input || $input == '%%' || $input == '%') {