Avoid a useless request

This commit is contained in:
emeric
2023-10-21 00:00:36 +02:00
parent d86260ba2d
commit 07f58b3d10
2 changed files with 9 additions and 10 deletions
+5 -6
View File
@@ -124,9 +124,10 @@ namespace API::Subsonic
} }
// Report the first GENRE for this track // Report the first GENRE for this track
if (ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") }) const ClusterType::pointer genreClusterType{ ClusterType::find(dbSession, "GENRE") };
if (genreClusterType)
{ {
auto clusters{ release->getClusterGroups({clusterType}, 1) }; auto clusters{ release->getClusterGroups({genreClusterType}, 1) };
if (!clusters.empty() && !clusters.front().empty()) if (!clusters.empty() && !clusters.front().empty())
albumNode.setAttribute("genre", clusters.front().front()->getName()); albumNode.setAttribute("genre", clusters.front().front()->getName());
} }
@@ -173,13 +174,11 @@ namespace API::Subsonic
// Genres // Genres
{ {
albumNode.createEmptyArrayChild("genres"); albumNode.createEmptyArrayChild("genres");
if (genreClusterType)
ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") };
if (clusterType)
{ {
Cluster::FindParameters params; Cluster::FindParameters params;
params.setRelease(release->getId()); params.setRelease(release->getId());
params.setClusterType(clusterType->getId()); params.setClusterType(genreClusterType->getId());
for (const ClusterId clusterId : Cluster::find(dbSession, params).results) for (const ClusterId clusterId : Cluster::find(dbSession, params).results)
{ {
+4 -4
View File
@@ -152,7 +152,8 @@ namespace API::Subsonic
trackResponse.setAttribute("starred", StringUtils::toISO8601String(dateTime)); trackResponse.setAttribute("starred", StringUtils::toISO8601String(dateTime));
// Report the first GENRE for this track // Report the first GENRE for this track
if (ClusterType::pointer genreClusterType{ ClusterType::find(dbSession, "GENRE") }) const ClusterType::pointer genreClusterType{ ClusterType::find(dbSession, "GENRE") };
if (genreClusterType)
{ {
auto clusters{ track->getClusterGroups({genreClusterType}, 1) }; auto clusters{ track->getClusterGroups({genreClusterType}, 1) };
if (!clusters.empty() && !clusters.front().empty()) if (!clusters.empty() && !clusters.front().empty())
@@ -235,12 +236,11 @@ namespace API::Subsonic
{ {
trackResponse.createEmptyArrayChild("genres"); trackResponse.createEmptyArrayChild("genres");
ClusterType::pointer clusterType{ ClusterType::find(dbSession, "GENRE") }; if (genreClusterType)
if (clusterType)
{ {
Cluster::FindParameters params; Cluster::FindParameters params;
params.setTrack(track->getId()); params.setTrack(track->getId());
params.setClusterType(clusterType->getId()); params.setClusterType(genreClusterType->getId());
for (const ClusterId clusterId : Cluster::find(dbSession, params).results) for (const ClusterId clusterId : Cluster::find(dbSession, params).results)
{ {