Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cast to into for search limit searches
  • Loading branch information
lachlan-00 committed Jan 19, 2023
1 parent 442cd6b commit c456e66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Module/Statistics/Stats.php
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/Repository/Model/Search.php
Expand Up @@ -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)";
Expand Down Expand Up @@ -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 ?";
Expand Down Expand Up @@ -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 == '%') {
Expand Down

0 comments on commit c456e66

Please sign in to comment.