SubsonicAPI: optimized search for tracks
This commit is contained in:
@@ -204,16 +204,13 @@ namespace API::Subsonic
|
||||
if (!user)
|
||||
throw UserNotAuthorizedError{};
|
||||
|
||||
const auto trackIds{ Track::find(context.dbSession, Track::FindParameters {}.setSortMethod(TrackSortMethod::Random).setRange({0, size})) };
|
||||
const auto tracks{ Track::find(context.dbSession, Track::FindParameters {}.setSortMethod(TrackSortMethod::Random).setRange({0, size})) };
|
||||
|
||||
Response response{ Response::createOkResponse(context.serverProtocolVersion) };
|
||||
|
||||
Response::Node& randomSongsNode{ response.createNode("randomSongs") };
|
||||
for (const TrackId trackId : trackIds.results)
|
||||
{
|
||||
const Track::pointer track{ Track::find(context.dbSession, trackId) };
|
||||
for (const Track::pointer& track : tracks.results)
|
||||
randomSongsNode.addArrayChild("song", createSongNode(context, track, user));
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -250,12 +247,9 @@ namespace API::Subsonic
|
||||
params.setClusters({ cluster->getId() });
|
||||
params.setRange({ offset, size });
|
||||
|
||||
auto trackIds{ Track::find(context.dbSession, params) };
|
||||
for (const TrackId trackId : trackIds.results)
|
||||
{
|
||||
const Track::pointer track{ Track::find(context.dbSession, trackId) };
|
||||
const auto tracks{ Track::find(context.dbSession, params) };
|
||||
for (const Track::pointer& track : tracks.results)
|
||||
songsByGenreNode.addArrayChild("song", createSongNode(context, track, user));
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace API::Subsonic
|
||||
params.setRange({ 0, meanTrackCountPerArtist });
|
||||
params.setSortMethod(TrackSortMethod::Random);
|
||||
|
||||
const auto artistTracks{ Track::find(context.dbSession, params) };
|
||||
const auto artistTracks{ Track::findIds(context.dbSession, params) };
|
||||
tracks.insert(std::end(tracks),
|
||||
std::begin(artistTracks.results),
|
||||
std::end(artistTracks.results));
|
||||
@@ -225,7 +225,7 @@ namespace API::Subsonic
|
||||
params.setRange({ 0, meanTrackCountPerRelease });
|
||||
params.setSortMethod(TrackSortMethod::Random);
|
||||
|
||||
const auto releaseTracks{ Track::find(context.dbSession, params) };
|
||||
const auto releaseTracks{ Track::findIds(context.dbSession, params) };
|
||||
tracks.insert(std::end(tracks),
|
||||
std::begin(releaseTracks.results),
|
||||
std::end(releaseTracks.results));
|
||||
@@ -349,11 +349,8 @@ namespace API::Subsonic
|
||||
directoryNode.setAttribute("name", Utils::makeNameFilesystemCompatible(release->getName()));
|
||||
|
||||
const auto tracks{ Track::find(context.dbSession, Track::FindParameters {}.setRelease(*releaseId).setSortMethod(TrackSortMethod::Release)) };
|
||||
for (const TrackId trackId : tracks.results)
|
||||
{
|
||||
const Track::pointer track{ Track::find(context.dbSession, trackId) };
|
||||
for (const Track::pointer& track : tracks.results)
|
||||
directoryNode.addArrayChild("child", createSongNode(context, track, user));
|
||||
}
|
||||
}
|
||||
else
|
||||
throw BadParameterGenericError{ "id" };
|
||||
@@ -432,11 +429,8 @@ namespace API::Subsonic
|
||||
Response::Node albumNode{ createAlbumNode(context, release, user, true /* id3 */) };
|
||||
|
||||
const auto tracks{ Track::find(context.dbSession, Track::FindParameters {}.setRelease(id).setSortMethod(TrackSortMethod::Release)) };
|
||||
for (const TrackId trackId : tracks.results)
|
||||
{
|
||||
const Track::pointer track{ Track::find(context.dbSession, trackId) };
|
||||
for (const Track::pointer& track : tracks.results)
|
||||
albumNode.addArrayChild("song", createSongNode(context, track, user));
|
||||
}
|
||||
|
||||
response.addNode("album", std::move(albumNode));
|
||||
|
||||
|
||||
@@ -86,8 +86,7 @@ namespace API::Subsonic
|
||||
params.setKeywords(keywords);
|
||||
params.setRange({ albumOffset, albumCount });
|
||||
|
||||
RangeResults<Release::pointer> releases{ Release::find(context.dbSession, params) };
|
||||
for (const Release::pointer& release : releases.results)
|
||||
for (const Release::pointer& release : Release::find(context.dbSession, params).results)
|
||||
searchResult2Node.addArrayChild("album", createAlbumNode(context, release, user, id3));
|
||||
}
|
||||
|
||||
@@ -97,12 +96,8 @@ namespace API::Subsonic
|
||||
params.setKeywords(keywords);
|
||||
params.setRange({ songOffset, songCount });
|
||||
|
||||
RangeResults<TrackId> trackIds{ Track::find(context.dbSession, params) };
|
||||
for (const TrackId trackId : trackIds.results)
|
||||
{
|
||||
const auto track{ Track::find(context.dbSession, trackId) };
|
||||
for (const Track::pointer& track : Track::find(context.dbSession, params).results)
|
||||
searchResult2Node.addArrayChild("song", createSongNode(context, track, user));
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
|
||||
@@ -110,6 +110,7 @@ namespace API::Subsonic
|
||||
trackResponse.setAttribute("playCount", Listen::getCount(context.dbSession, user->getId(), user->getScrobblingBackend(), track->getId()));
|
||||
trackResponse.setAttribute("path", getTrackPath(track));
|
||||
{
|
||||
// TODO, store this in DB
|
||||
std::error_code ec;
|
||||
const auto fileSize{ std::filesystem::file_size(track->getPath(), ec) };
|
||||
if (!ec)
|
||||
|
||||
Reference in New Issue
Block a user