No need to full rescan when changing some settings
This commit is contained in:
@@ -35,7 +35,7 @@ namespace lms::db
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 86 };
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 87 };
|
||||
}
|
||||
|
||||
VersionInfo::VersionInfo()
|
||||
@@ -1178,6 +1178,12 @@ FROM tracklist)");
|
||||
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET scan_version = scan_version + 1");
|
||||
}
|
||||
|
||||
void migrateFromV86(Session& session)
|
||||
{
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE scan_settings ADD COLUMN name TEXT NON NULL DEFAULT('')");
|
||||
utils::executeCommand(*session.getDboSession(), "ALTER TABLE scan_settings RENAME COLUMN scan_version TO audio_scan_version");
|
||||
}
|
||||
|
||||
bool doDbMigration(Session& session)
|
||||
{
|
||||
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
|
||||
@@ -1240,6 +1246,7 @@ FROM tracklist)");
|
||||
{ 83, migrateFromV83 },
|
||||
{ 84, migrateFromV84 },
|
||||
{ 85, migrateFromV85 },
|
||||
{ 86, migrateFromV86 },
|
||||
};
|
||||
|
||||
bool migrationPerformed{};
|
||||
|
||||
@@ -26,24 +26,25 @@
|
||||
#include "database/Session.hpp"
|
||||
|
||||
#include "Utils.hpp"
|
||||
#include "traits/StringViewTraits.hpp"
|
||||
|
||||
namespace lms::db
|
||||
{
|
||||
void ScanSettings::init(Session& session)
|
||||
ScanSettings::ScanSettings(std::string_view name)
|
||||
: _name{ name }
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
|
||||
if (pointer settings{ get(session) })
|
||||
return;
|
||||
|
||||
session.getDboSession()->add(std::make_unique<ScanSettings>());
|
||||
}
|
||||
|
||||
ScanSettings::pointer ScanSettings::get(Session& session)
|
||||
ScanSettings::pointer ScanSettings::create(Session& session, std::string_view name)
|
||||
{
|
||||
return session.getDboSession()->add(std::unique_ptr<ScanSettings>(new ScanSettings{ name }));
|
||||
}
|
||||
|
||||
ScanSettings::pointer ScanSettings::get(Session& session, std::string_view name)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->find<ScanSettings>());
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->find<ScanSettings>().where("name = ?").bind(name));
|
||||
}
|
||||
|
||||
std::vector<std::string_view> ScanSettings::getExtraTagsToScan() const
|
||||
@@ -69,7 +70,7 @@ namespace lms::db
|
||||
{
|
||||
std::string newTagsToScan{ core::stringUtils::joinStrings(extraTags, ";") };
|
||||
if (newTagsToScan != _extraTagsToScan)
|
||||
incScanVersion();
|
||||
incAudioScanVersion();
|
||||
|
||||
_extraTagsToScan = std::move(newTagsToScan);
|
||||
}
|
||||
@@ -80,7 +81,7 @@ namespace lms::db
|
||||
if (tagDelimiters != _artistTagDelimiters)
|
||||
{
|
||||
_artistTagDelimiters.swap(tagDelimiters);
|
||||
incScanVersion();
|
||||
incAudioScanVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,30 +91,24 @@ namespace lms::db
|
||||
if (tagDelimiters != _defaultTagDelimiters)
|
||||
{
|
||||
_defaultTagDelimiters.swap(tagDelimiters);
|
||||
incScanVersion();
|
||||
incAudioScanVersion();
|
||||
}
|
||||
}
|
||||
|
||||
void ScanSettings::setSkipSingleReleasePlayLists(bool value)
|
||||
{
|
||||
if (_skipSingleReleasePlayLists != value)
|
||||
{
|
||||
_skipSingleReleasePlayLists = value;
|
||||
incScanVersion();
|
||||
}
|
||||
}
|
||||
|
||||
void ScanSettings::setAllowMBIDArtistMerge(bool value)
|
||||
{
|
||||
if (_allowMBIDArtistMerge != value)
|
||||
{
|
||||
_allowMBIDArtistMerge = value;
|
||||
incScanVersion();
|
||||
}
|
||||
}
|
||||
|
||||
void ScanSettings::incScanVersion()
|
||||
void ScanSettings::incAudioScanVersion()
|
||||
{
|
||||
_scanVersion += 1;
|
||||
_audioScanVersion += 1;
|
||||
}
|
||||
} // namespace lms::db
|
||||
|
||||
@@ -180,7 +180,9 @@ namespace lms::db
|
||||
// TODO: move this elsewhere
|
||||
{
|
||||
auto uniqueTransaction{ createWriteTransaction() };
|
||||
ScanSettings::init(*this);
|
||||
|
||||
if (!ScanSettings::get(*this))
|
||||
create<ScanSettings>();
|
||||
}
|
||||
|
||||
return migrationPerformed;
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -58,12 +57,12 @@ namespace lms::db
|
||||
None,
|
||||
};
|
||||
|
||||
static void init(Session& session);
|
||||
ScanSettings() = default;
|
||||
|
||||
static pointer get(Session& session);
|
||||
static pointer get(Session& session, std::string_view name = "");
|
||||
|
||||
// Getters
|
||||
std::size_t getScanVersion() const { return _scanVersion; }
|
||||
std::size_t getAudioScanVersion() const { return _audioScanVersion; }
|
||||
Wt::WTime getUpdateStartTime() const { return _startTime; }
|
||||
UpdatePeriod getUpdatePeriod() const { return _updatePeriod; }
|
||||
std::vector<std::string_view> getExtraTagsToScan() const;
|
||||
@@ -82,12 +81,12 @@ namespace lms::db
|
||||
void setDefaultTagDelimiters(std::span<const std::string_view> delimiters);
|
||||
void setSkipSingleReleasePlayLists(bool value);
|
||||
void setAllowMBIDArtistMerge(bool value);
|
||||
void incScanVersion();
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _scanVersion, "scan_version");
|
||||
Wt::Dbo::field(a, _name, "name");
|
||||
Wt::Dbo::field(a, _audioScanVersion, "audio_scan_version");
|
||||
Wt::Dbo::field(a, _startTime, "start_time");
|
||||
Wt::Dbo::field(a, _updatePeriod, "update_period");
|
||||
Wt::Dbo::field(a, _similarityEngineType, "similarity_engine_type");
|
||||
@@ -99,7 +98,15 @@ namespace lms::db
|
||||
}
|
||||
|
||||
private:
|
||||
int _scanVersion{};
|
||||
friend class Session;
|
||||
|
||||
ScanSettings(std::string_view name);
|
||||
static pointer create(Session& session, std::string_view name = "");
|
||||
|
||||
void incAudioScanVersion();
|
||||
|
||||
std::string _name;
|
||||
int _audioScanVersion{};
|
||||
Wt::WTime _startTime = Wt::WTime{ 0, 0, 0 };
|
||||
UpdatePeriod _updatePeriod{ UpdatePeriod::Never };
|
||||
SimilarityEngineType _similarityEngineType{ SimilarityEngineType::Clusters };
|
||||
|
||||
Reference in New Issue
Block a user