search3: minor optim
This commit is contained in:
@@ -867,14 +867,11 @@ namespace lms::db
|
|||||||
for (const std::string& bindArg : where.getBindArgs())
|
for (const std::string& bindArg : where.getBindArgs())
|
||||||
query.bind(bindArg);
|
query.bind(bindArg);
|
||||||
|
|
||||||
auto queryRes{ query.resultList() };
|
|
||||||
|
|
||||||
std::map<ClusterTypeId, std::vector<Cluster::pointer>> clustersByType;
|
std::map<ClusterTypeId, std::vector<Cluster::pointer>> clustersByType;
|
||||||
for (const Wt::Dbo::ptr<Cluster>& cluster : queryRes)
|
utils::forEachQueryResult(query, [&](const Wt::Dbo::ptr<Cluster>& cluster) {
|
||||||
{
|
|
||||||
if (clustersByType[cluster->getType()->getId()].size() < size)
|
if (clustersByType[cluster->getType()->getId()].size() < size)
|
||||||
clustersByType[cluster->getType()->getId()].push_back(cluster);
|
clustersByType[cluster->getType()->getId()].push_back(cluster);
|
||||||
}
|
});
|
||||||
|
|
||||||
std::vector<std::vector<Cluster::pointer>> res;
|
std::vector<std::vector<Cluster::pointer>> res;
|
||||||
for (const auto& [clusterTypeId, clusters] : clustersByType)
|
for (const auto& [clusterTypeId, clusters] : clustersByType)
|
||||||
@@ -882,4 +879,23 @@ namespace lms::db
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ObjectPtr<Cluster>> Release::getClusters(ClusterTypeId clusterTypeId, std::size_t maxCount) const
|
||||||
|
{
|
||||||
|
assert(session());
|
||||||
|
|
||||||
|
auto query{ session()->query<Wt::Dbo::ptr<Cluster>>("SELECT c FROM cluster c INNER JOIN track_cluster t_c ON t_c.cluster_id = c.id INNER JOIN track t ON t.id = t_c.track_id")
|
||||||
|
.where("t.release_id = ?").bind(getId())
|
||||||
|
.where("c.cluster_type_id = ?").bind(clusterTypeId.toString())
|
||||||
|
.groupBy("c.id")
|
||||||
|
.orderBy("COUNT(c.id) DESC")
|
||||||
|
.limit(static_cast<int>(maxCount)) };
|
||||||
|
|
||||||
|
std::vector<ObjectPtr<Cluster>> res;
|
||||||
|
utils::forEachQueryResult(query, [&](const Wt::Dbo::ptr<Cluster>& cluster) {
|
||||||
|
res.push_back(cluster);
|
||||||
|
});
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
} // namespace lms::db
|
} // namespace lms::db
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ namespace lms::db
|
|||||||
// Each clusters are grouped by cluster type, sorted by the number of occurence (max to min)
|
// Each clusters are grouped by cluster type, sorted by the number of occurence (max to min)
|
||||||
// size is the max number of cluster per cluster type
|
// size is the max number of cluster per cluster type
|
||||||
std::vector<std::vector<ObjectPtr<Cluster>>> getClusterGroups(const std::vector<ClusterTypeId>& clusterTypeIds, std::size_t size) const;
|
std::vector<std::vector<ObjectPtr<Cluster>>> getClusterGroups(const std::vector<ClusterTypeId>& clusterTypeIds, std::size_t size) const;
|
||||||
|
std::vector<ObjectPtr<Cluster>> getClusters(ClusterTypeId clusterTypeId, std::size_t maxCount) const;
|
||||||
|
|
||||||
// Utility functions (if all tracks have the same values, which is legit to not be the case)
|
// Utility functions (if all tracks have the same values, which is legit to not be the case)
|
||||||
core::PartialDateTime getDate() const;
|
core::PartialDateTime getDate() const;
|
||||||
|
|||||||
@@ -131,9 +131,9 @@ namespace lms::api::subsonic
|
|||||||
const ClusterType::pointer genreClusterType{ ClusterType::find(context.dbSession, "GENRE") };
|
const ClusterType::pointer genreClusterType{ ClusterType::find(context.dbSession, "GENRE") };
|
||||||
if (genreClusterType)
|
if (genreClusterType)
|
||||||
{
|
{
|
||||||
auto clusters{ release->getClusterGroups({ genreClusterType->getId() }, 1) };
|
const auto clusters{ release->getClusters(genreClusterType->getId(), 1) };
|
||||||
if (!clusters.empty() && !clusters.front().empty())
|
if (!clusters.empty())
|
||||||
albumNode.setAttribute("genre", clusters.front().front()->getName());
|
albumNode.setAttribute("genre", clusters.front()->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const Wt::WDateTime dateTime{ core::Service<feedback::IFeedbackService>::get()->getStarredDateTime(context.user->getId(), release->getId()) }; dateTime.isValid())
|
if (const Wt::WDateTime dateTime{ core::Service<feedback::IFeedbackService>::get()->getStarredDateTime(context.user->getId(), release->getId()) }; dateTime.isValid())
|
||||||
|
|||||||
Reference in New Issue
Block a user