Various minor cleanup

This commit is contained in:
emeric
2024-12-05 20:09:14 +01:00
parent 76b9c1fe10
commit 45175a721c
35 changed files with 104 additions and 137 deletions
+6 -6
View File
@@ -29,7 +29,6 @@
#include "database/Track.hpp"
#include "database/User.hpp"
#include "EnumSetTraits.hpp"
#include "IdTypeTraits.hpp"
#include "SqlQuery.hpp"
#include "Utils.hpp"
@@ -182,16 +181,16 @@ namespace lms::db
}
} // namespace
Artist::Artist(const std::string& name, const std::optional<core::UUID>& MBID)
: _MBID{ MBID ? MBID->getAsString() : "" }
Artist::Artist(const std::string& name, const std::optional<core::UUID>& mbid)
: _mbid{ mbid ? mbid->getAsString() : "" }
{
setName(name);
_sortName = _name;
}
Artist::pointer Artist::create(Session& session, const std::string& name, const std::optional<core::UUID>& MBID)
Artist::pointer Artist::create(Session& session, const std::string& name, const std::optional<core::UUID>& mbid)
{
return session.getDboSession()->add(std::unique_ptr<Artist>{ new Artist{ name, MBID } });
return session.getDboSession()->add(std::unique_ptr<Artist>{ new Artist{ name, mbid } });
}
std::size_t Artist::getCount(Session& session)
@@ -322,7 +321,7 @@ namespace lms::db
return utils::execRangeQuery<ArtistId>(query, range);
}
std::vector<std::vector<Cluster::pointer>> Artist::getClusterGroups(std::vector<ClusterTypeId> clusterTypeIds, std::size_t size) const
std::vector<std::vector<Cluster::pointer>> Artist::getClusterGroups(std::span<const ClusterTypeId> clusterTypeIds, std::size_t size) const
{
assert(session());
@@ -354,6 +353,7 @@ namespace lms::db
});
std::vector<std::vector<Cluster::pointer>> res;
res.reserve(clustersByType.size());
for (const auto& [clusterTypeId, clusters] : clustersByType)
res.push_back(clusters);
-1
View File
@@ -24,7 +24,6 @@
#include "core/IConfig.hpp"
#include "core/ILogger.hpp"
#include "core/ITraceLogger.hpp"
#include "core/Service.hpp"
#include "database/Session.hpp"
#include "database/User.hpp"
+2 -2
View File
@@ -71,11 +71,11 @@ namespace lms::db
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Image>>("SELECT i from image i").where("i.id = ?").bind(id));
}
Image::pointer Image::find(Session& session, const std::filesystem::path& path)
Image::pointer Image::find(Session& session, const std::filesystem::path& file)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Image>>("SELECT i from image i").where("i.absolute_file_path = ?").bind(path));
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<Image>>("SELECT i from image i").where("i.absolute_file_path = ?").bind(file));
}
void Image::find(Session& session, ImageId& lastRetrievedImage, std::size_t count, const std::function<void(const Image::pointer&)>& func)
@@ -130,16 +130,16 @@ namespace lms::db
static pointer find(Session& session, ArtistId id);
static std::vector<pointer> find(Session& session, std::string_view name); // exact match on name field
static void find(Session& session, ArtistId& lastRetrievedArtist, std::size_t count, const std::function<void(const Artist::pointer&)>& func, MediaLibraryId library = {});
static RangeResults<pointer> find(Session& session, const FindParameters& parameters);
static void find(Session& session, const FindParameters& parameters, std::function<void(const pointer&)> func);
static RangeResults<ArtistId> findIds(Session& session, const FindParameters& parameters);
static RangeResults<pointer> find(Session& session, const FindParameters& params);
static void find(Session& session, const FindParameters& params, std::function<void(const pointer&)> func);
static RangeResults<ArtistId> findIds(Session& session, const FindParameters& params);
static RangeResults<ArtistId> findOrphanIds(Session& session, std::optional<Range> range = std::nullopt); // No track related
static bool exists(Session& session, ArtistId id);
// Accessors
const std::string& getName() const { return _name; }
const std::string& getSortName() const { return _sortName; }
std::optional<core::UUID> getMBID() const { return core::UUID::fromString(_MBID); }
std::optional<core::UUID> getMBID() const { return core::UUID::fromString(_mbid); }
ObjectPtr<Image> getImage() const;
// No artistLinkTypes means get them all
@@ -148,10 +148,10 @@ namespace lms::db
// Get the cluster of the tracks made by this artist
// Each clusters are grouped by cluster type, sorted by the number of occurence
// size is the max number of cluster per cluster type
std::vector<std::vector<ObjectPtr<Cluster>>> getClusterGroups(std::vector<ClusterTypeId> clusterTypeIds, std::size_t size) const;
std::vector<std::vector<ObjectPtr<Cluster>>> getClusterGroups(std::span<const ClusterTypeId> clusterTypeIds, std::size_t size) const;
void setName(std::string_view name);
void setMBID(const std::optional<core::UUID>& mbid) { _MBID = mbid ? mbid->getAsString() : ""; }
void setMBID(const std::optional<core::UUID>& mbid) { _mbid = mbid ? mbid->getAsString() : ""; }
void setSortName(std::string_view sortName);
void setImage(ObjectPtr<Image> image);
@@ -160,7 +160,7 @@ namespace lms::db
{
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::field(a, _sortName, "sort_name");
Wt::Dbo::field(a, _MBID, "mbid");
Wt::Dbo::field(a, _mbid, "mbid");
Wt::Dbo::belongsTo(a, _image, "image", Wt::Dbo::OnDeleteSetNull);
Wt::Dbo::hasMany(a, _trackArtistLinks, Wt::Dbo::ManyToOne, "artist");
@@ -173,11 +173,11 @@ namespace lms::db
friend class Session;
// Create
Artist(const std::string& name, const std::optional<core::UUID>& MBID = {});
static pointer create(Session& session, const std::string& name, const std::optional<core::UUID>& UUID = {});
static pointer create(Session& session, const std::string& name, const std::optional<core::UUID>& mbid = std::nullopt);
std::string _name;
std::string _sortName;
std::string _MBID; // Musicbrainz Identifier
std::string _mbid; // Musicbrainz Identifier
Wt::Dbo::ptr<Image> _image;
Wt::Dbo::collection<Wt::Dbo::ptr<TrackArtistLink>> _trackArtistLinks; // Tracks involving this artist