Skip to content

Commit

Permalink
update artist_songs to browse
Browse files Browse the repository at this point in the history
* set priority of joins a bit clearer so they are ordered by importance when there are more than one
  • Loading branch information
lachlan-00 committed May 14, 2024
1 parent 01961a6 commit c9676aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
29 changes: 18 additions & 11 deletions src/Module/Api/Method/ArtistSongsMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use Ampache\Module\Api\Api;
use Ampache\Module\Api\Json_Data;
use Ampache\Module\Api\Xml_Data;
use Ampache\Repository\SongRepositoryInterface;

/**
* Class ArtistSongsMethod
Expand Down Expand Up @@ -65,9 +64,24 @@ public static function artist_songs(array $input, User $user): bool

return false;
}
$results = (array_key_exists('top50', $input) && (int)$input['top50'] == 1)
? static::getSongRepository()->getTopSongsByArtist($artist)
: static::getSongRepository()->getByArtist($object_id);

$browse = Api::getBrowse();
$browse->reset_filters();
$browse->set_type('song');
if (array_key_exists('top50', $input) && (int)$input['top50'] == 1) {
$browse->set_start(0);
$browse->set_offset(50);
$browse->set_is_simple(true);
$browse->set_sort('object_count', 'DESC');
$type = 'top50';
} else {
$browse->set_sort('name', 'ASC');
$type = 'artist';
}

$browse->set_filter($type, $object_id);

$results = $browse->get_objects();
if (empty($results)) {
Api::empty('song', $input['api_format']);

Expand All @@ -89,11 +103,4 @@ public static function artist_songs(array $input, User $user): bool

return true;
}

private static function getSongRepository(): SongRepositoryInterface
{
global $dic;

return $dic->get(SongRepositoryInterface::class);
}
}
4 changes: 2 additions & 2 deletions src/Module/Database/Query/AlbumDiskQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function get_sorts(): array
public function get_sql_filter($query, $filter, $value): string
{
$filter_sql = '';
$query->set_join('LEFT', '`album`', '`album_disk`.`album_id`', '`album`.`id`', 100);
$query->set_join('LEFT', '`album`', '`album_disk`.`album_id`', '`album`.`id`', 10);
switch ($filter) {
case 'tag':
$query->set_join('LEFT', '`tag_map`', '`tag_map`.`object_id`', '`album`.`id`', 100);
Expand Down Expand Up @@ -246,7 +246,7 @@ public function get_sql_sort($query, $field, $order): string
break;
case 'artist':
$sql = "`artist`.`name`";
$query->set_join('LEFT', '`song`', '`song`.`album`', '`album`.`id`', 100);
$query->set_join('LEFT', '`song`', '`song`.`album`', '`album`.`id`', 50);
$query->set_join('LEFT', '`artist`', '`song`.`artist`', '`artist`.`id`', 100);
break;
case 'rating':
Expand Down
4 changes: 2 additions & 2 deletions src/Module/Database/Query/AlbumQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function get_sql_sort($query, $field, $order): string
break;
case 'generic_artist':
$sql = "`artist`.`name`";
$query->set_join('LEFT', '`song`', '`song`.`album`', '`album`.`id`', 100);
$query->set_join('LEFT', '`song`', '`song`.`album`', '`album`.`id`', 50);
$query->set_join(
'LEFT',
'`artist`',
Expand All @@ -239,7 +239,7 @@ public function get_sql_sort($query, $field, $order): string
break;
case 'artist':
$sql = "`artist`.`name`";
$query->set_join('LEFT', '`song`', '`song`.`album`', '`album`.`id`', 100);
$query->set_join('LEFT', '`song`', '`song`.`album`', '`album`.`id`', 50);
$query->set_join('LEFT', '`artist`', '`song`.`artist`', '`artist`.`id`', 100);
break;
case 'rating':
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Database/Query/ArtistQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function get_sql_filter($query, $filter, $value): string
if ($query->get_filter('song_artist')) {
$type = '\'song_artist\'';
}
$query->set_join_and('LEFT', '`catalog_map`', '`catalog_map`.`object_id`', '`artist`.`id`', '`catalog_map`.`object_type`', $type, 100);
$query->set_join_and('LEFT', '`catalog_map`', '`catalog_map`.`object_id`', '`artist`.`id`', '`catalog_map`.`object_type`', $type, 50);
$query->set_join('LEFT', '`catalog`', '`catalog`.`id`', '`catalog_map`.`catalog_id`', 100);
$filter_sql = " `catalog`.`enabled` = '1' AND ";
break;
Expand Down

0 comments on commit c9676aa

Please sign in to comment.