Fixed bad access since some tracks may be duplicated in the database
This commit is contained in:
@@ -152,13 +152,15 @@ Track::getById(Session& session, IdType id)
|
||||
.where("id = ?").bind(id);
|
||||
}
|
||||
|
||||
Track::pointer
|
||||
std::vector<Track::pointer>
|
||||
Track::getByRecordingMBID(Session& session, const UUID& mbid)
|
||||
{
|
||||
session.checkSharedLocked();
|
||||
|
||||
return session.getDboSession().find<Track>()
|
||||
Wt::Dbo::collection<Track::pointer> res = session.getDboSession().find<Track>()
|
||||
.where("recording_mbid = ?").bind(std::string {mbid.getAsString()});
|
||||
|
||||
return std::vector<Track::pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
Track::pointer
|
||||
|
||||
@@ -62,7 +62,7 @@ class Track : public Wt::Dbo::Dbo<Track>
|
||||
static std::size_t getCount(Session& session);
|
||||
static pointer getByPath(Session& session, const std::filesystem::path& p);
|
||||
static pointer getById(Session& session, IdType id);
|
||||
static pointer getByRecordingMBID(Session& session, const UUID& MBID);
|
||||
static std::vector<pointer> getByRecordingMBID(Session& session, const UUID& MBID);
|
||||
static std::vector<pointer> getSimilarTracks(Session& session,
|
||||
const std::unordered_set<IdType>& trackIds,
|
||||
std::optional<std::size_t> offset = {},
|
||||
|
||||
@@ -130,7 +130,12 @@ namespace
|
||||
{
|
||||
const Wt::Json::Object& additionalInfo = metadata.get("additional_info");
|
||||
if (std::optional<UUID> recordingMBID {UUID::fromString(additionalInfo.get("recording_mbid").orIfNull(""))})
|
||||
track = Database::Track::getByRecordingMBID(session, *recordingMBID);
|
||||
{
|
||||
const auto tracks {Database::Track::getByRecordingMBID(session, *recordingMBID)};
|
||||
// if duplicated files, do not record it (let the user correct its database)
|
||||
if (tracks.size() == 1)
|
||||
track = tracks.front();
|
||||
}
|
||||
}
|
||||
|
||||
if (track)
|
||||
|
||||
Reference in New Issue
Block a user