Added a way to set artists that must not be split, fixes #522
This commit is contained in:
@@ -35,7 +35,7 @@ namespace lms::db
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 87 };
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 88 };
|
||||
}
|
||||
|
||||
VersionInfo::VersionInfo()
|
||||
@@ -1184,6 +1184,11 @@ FROM tracklist)");
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE scan_settings RENAME COLUMN scan_version TO audio_scan_version");
|
||||
}
|
||||
|
||||
void migrateFromV87(Session& session)
|
||||
{
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE scan_settings ADD COLUMN artists_to_not_split TEXT NON NULL DEFAULT('')");
|
||||
}
|
||||
|
||||
bool doDbMigration(Session& session)
|
||||
{
|
||||
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
||||
@@ -1247,6 +1252,7 @@ FROM tracklist)");
|
||||
{ 84, migrateFromV84 },
|
||||
{ 85, migrateFromV85 },
|
||||
{ 86, migrateFromV86 },
|
||||
{ 87, migrateFromV87 },
|
||||
};
|
||||
|
||||
bool migrationPerformed{};
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "database/Session.hpp"
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "traits/IdTypeTraits.hpp"
|
||||
#include "traits/StringViewTraits.hpp"
|
||||
|
||||
namespace lms::db
|
||||
@@ -40,7 +41,14 @@ namespace lms::db
|
||||
return session.getDboSession()->add(std::unique_ptr<ScanSettings>(new ScanSettings{ name }));
|
||||
}
|
||||
|
||||
ScanSettings::pointer ScanSettings::get(Session& session, std::string_view name)
|
||||
ScanSettings::pointer ScanSettings::find(Session& session, ScanSettingsId id)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->query<Wt::Dbo::ptr<ScanSettings>>("SELECT s_s from scan_settings s_s").where("s_s.id = ?").bind(id));
|
||||
}
|
||||
|
||||
ScanSettings::pointer ScanSettings::find(Session& session, std::string_view name)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
@@ -66,13 +74,19 @@ namespace lms::db
|
||||
return core::stringUtils::splitEscapedStrings(_defaultTagDelimiters, ';', '\\');
|
||||
}
|
||||
|
||||
std::vector<std::string> ScanSettings::getArtistsToNotSplit() const
|
||||
{
|
||||
return core::stringUtils::splitEscapedStrings(_artistsToNotSplit, ';', '\\');
|
||||
}
|
||||
|
||||
void ScanSettings::setExtraTagsToScan(std::span<const std::string_view> extraTags)
|
||||
{
|
||||
std::string newTagsToScan{ core::stringUtils::joinStrings(extraTags, ";") };
|
||||
if (newTagsToScan != _extraTagsToScan)
|
||||
{
|
||||
_extraTagsToScan.swap(newTagsToScan);
|
||||
incAudioScanVersion();
|
||||
|
||||
_extraTagsToScan = std::move(newTagsToScan);
|
||||
}
|
||||
}
|
||||
|
||||
void ScanSettings::setArtistTagDelimiters(std::span<const std::string_view> delimiters)
|
||||
@@ -85,6 +99,16 @@ namespace lms::db
|
||||
}
|
||||
}
|
||||
|
||||
void ScanSettings::setArtistsToNotSplit(std::span<const std::string_view> artists)
|
||||
{
|
||||
std::string artistsToNotSplit{ core::stringUtils::escapeAndJoinStrings(artists, ';', '\\') };
|
||||
if (artistsToNotSplit != _artistsToNotSplit)
|
||||
{
|
||||
_artistsToNotSplit.swap(artistsToNotSplit);
|
||||
incAudioScanVersion();
|
||||
}
|
||||
}
|
||||
|
||||
void ScanSettings::setDefaultTagDelimiters(std::span<const std::string_view> delimiters)
|
||||
{
|
||||
std::string tagDelimiters{ core::stringUtils::escapeAndJoinStrings(delimiters, ';', '\\') };
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace lms::db
|
||||
{
|
||||
auto uniqueTransaction{ createWriteTransaction() };
|
||||
|
||||
if (!ScanSettings::get(*this))
|
||||
if (!ScanSettings::find(*this))
|
||||
create<ScanSettings>();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@ namespace lms::db
|
||||
|
||||
ScanSettings() = default;
|
||||
|
||||
static pointer get(Session& session, std::string_view name = "");
|
||||
static pointer find(Session& session, std::string_view name = "");
|
||||
static pointer find(Session& session, ScanSettingsId id);
|
||||
|
||||
// Getters
|
||||
std::size_t getAudioScanVersion() const { return _audioScanVersion; }
|
||||
@@ -69,6 +70,7 @@ namespace lms::db
|
||||
SimilarityEngineType getSimilarityEngineType() const { return _similarityEngineType; }
|
||||
std::vector<std::string> getArtistTagDelimiters() const;
|
||||
std::vector<std::string> getDefaultTagDelimiters() const;
|
||||
std::vector<std::string> getArtistsToNotSplit() const;
|
||||
bool getSkipSingleReleasePlayLists() const { return _skipSingleReleasePlayLists; }
|
||||
bool getAllowMBIDArtistMerge() const { return _allowMBIDArtistMerge; }
|
||||
|
||||
@@ -78,6 +80,7 @@ namespace lms::db
|
||||
void setExtraTagsToScan(std::span<const std::string_view> extraTags);
|
||||
void setSimilarityEngineType(SimilarityEngineType type) { _similarityEngineType = type; }
|
||||
void setArtistTagDelimiters(std::span<const std::string_view> delimiters);
|
||||
void setArtistsToNotSplit(std::span<const std::string_view> artists);
|
||||
void setDefaultTagDelimiters(std::span<const std::string_view> delimiters);
|
||||
void setSkipSingleReleasePlayLists(bool value);
|
||||
void setAllowMBIDArtistMerge(bool value);
|
||||
@@ -92,6 +95,7 @@ namespace lms::db
|
||||
Wt::Dbo::field(a, _similarityEngineType, "similarity_engine_type");
|
||||
Wt::Dbo::field(a, _extraTagsToScan, "extra_tags_to_scan");
|
||||
Wt::Dbo::field(a, _artistTagDelimiters, "artist_tag_delimiters");
|
||||
Wt::Dbo::field(a, _artistsToNotSplit, "artists_to_not_split");
|
||||
Wt::Dbo::field(a, _defaultTagDelimiters, "default_tag_delimiters");
|
||||
Wt::Dbo::field(a, _skipSingleReleasePlayLists, "skip_single_release_playlists");
|
||||
Wt::Dbo::field(a, _allowMBIDArtistMerge, "allow_mbid_artist_merge");
|
||||
@@ -112,6 +116,7 @@ namespace lms::db
|
||||
SimilarityEngineType _similarityEngineType{ SimilarityEngineType::Clusters };
|
||||
std::string _extraTagsToScan;
|
||||
std::string _artistTagDelimiters;
|
||||
std::string _artistsToNotSplit;
|
||||
std::string _defaultTagDelimiters;
|
||||
bool _skipSingleReleasePlayLists{};
|
||||
bool _allowMBIDArtistMerge{};
|
||||
|
||||
@@ -15,6 +15,7 @@ add_executable(test-database
|
||||
RatedRelease.cpp
|
||||
RatedTrack.cpp
|
||||
Release.cpp
|
||||
ScanSettings.cpp
|
||||
StarredArtist.cpp
|
||||
StarredRelease.cpp
|
||||
StarredTrack.cpp
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "database/RatedArtist.hpp"
|
||||
#include "database/RatedRelease.hpp"
|
||||
#include "database/RatedTrack.hpp"
|
||||
#include "database/ScanSettings.hpp"
|
||||
#include "database/StarredArtist.hpp"
|
||||
#include "database/StarredRelease.hpp"
|
||||
#include "database/StarredTrack.hpp"
|
||||
@@ -362,6 +363,7 @@ VALUES
|
||||
EXPECT_FALSE(RatedTrack::find(session, RatedTrackId{}));
|
||||
EXPECT_FALSE(Release::find(session, ReleaseId{}));
|
||||
EXPECT_FALSE(ReleaseType::find(session, ReleaseTypeId{}));
|
||||
EXPECT_FALSE(ScanSettings::find(session, ScanSettingsId{}));
|
||||
EXPECT_FALSE(StarredArtist::find(session, StarredArtistId{}));
|
||||
EXPECT_FALSE(StarredRelease::find(session, StarredReleaseId{}));
|
||||
EXPECT_FALSE(StarredTrack::find(session, StarredTrackId{}));
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "database/ScanSettings.hpp"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
#include "Common.hpp"
|
||||
|
||||
namespace lms::db::tests
|
||||
{
|
||||
using ScopedScanSettings = ScopedEntity<db::ScanSettings>;
|
||||
|
||||
TEST_F(DatabaseFixture, ScanSettings)
|
||||
{
|
||||
ScopedScanSettings settings{ session, "test" };
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
const auto artists{ settings.get()->getArtistsToNotSplit() };
|
||||
ASSERT_EQ(artists.size(), 0);
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
settings.get().modify()->setArtistsToNotSplit(std::initializer_list<std::string_view>{ "AC/DC", "My/Artist" });
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
const auto artists{ settings.get()->getArtistsToNotSplit() };
|
||||
ASSERT_EQ(artists.size(), 2);
|
||||
}
|
||||
}
|
||||
} // namespace lms::db::tests
|
||||
Reference in New Issue
Block a user