Simplified logger configuration, it no longer depends on Wt
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
#include "services/database/Session.hpp"
|
||||
#include "services/database/Track.hpp"
|
||||
#include "services/database/User.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "SqlQuery.hpp"
|
||||
#include "Utils.hpp"
|
||||
#include "EnumSetTraits.hpp"
|
||||
|
||||
@@ -157,7 +157,7 @@ namespace Database
|
||||
{
|
||||
}
|
||||
|
||||
ClusterType::pointer ClusterType::create(Session& session, const std::string& name)
|
||||
ClusterType::pointer ClusterType::create(Session& session, std::string_view name)
|
||||
{
|
||||
return session.getDboSession().add(std::unique_ptr<ClusterType> {new ClusterType{ name }});
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "services/database/User.hpp"
|
||||
#include "utils/IConfig.hpp"
|
||||
#include "utils/Service.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
|
||||
namespace Database
|
||||
{
|
||||
@@ -65,18 +65,18 @@ namespace Database
|
||||
|
||||
void prepare()
|
||||
{
|
||||
LMS_LOG(DB, DEBUG) << "Setting per-connection settings...";
|
||||
LMS_LOG(DB, DEBUG, "Setting per-connection settings...");
|
||||
executeSql("pragma journal_mode=WAL");
|
||||
executeSql("pragma synchronous=normal");
|
||||
executeSql("pragma analysis_limit=2000"); // to help make analyze command faster, 1000 does not seem to be enough to speed up all queries
|
||||
LMS_LOG(DB, DEBUG) << "Setting per-connection settings done!";
|
||||
LMS_LOG(DB, DEBUG, "Setting per-connection settings done!");
|
||||
}
|
||||
|
||||
void optimize()
|
||||
{
|
||||
LMS_LOG(DB, DEBUG) << "connection close: Running pragma optimize...";
|
||||
LMS_LOG(DB, DEBUG, "connection close: Running pragma optimize...");
|
||||
executeSql("pragma optimize");
|
||||
LMS_LOG(DB, DEBUG) << "connection close: pragma optimize complete";
|
||||
LMS_LOG(DB, DEBUG, "connection close: pragma optimize complete");
|
||||
}
|
||||
|
||||
std::filesystem::path _dbPath;
|
||||
@@ -86,7 +86,7 @@ namespace Database
|
||||
// Session living class handling the database and the login
|
||||
Db::Db(const std::filesystem::path& dbPath, std::size_t connectionCount)
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Creating connection pool on file " << dbPath.string();
|
||||
LMS_LOG(DB, INFO, "Creating connection pool on file " << dbPath.string());
|
||||
|
||||
auto connection{ std::make_unique<Connection>(dbPath.string()) };
|
||||
if (IConfig * config{ Service<IConfig>::get() })// may not be here on testU
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "services/database/Session.hpp"
|
||||
#include "services/database/User.hpp"
|
||||
#include "utils/Exception.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
|
||||
namespace Database
|
||||
{
|
||||
@@ -282,11 +282,11 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
|
||||
try
|
||||
{
|
||||
version = VersionInfo::getOrCreate(session)->getVersion();
|
||||
LMS_LOG(DB, INFO) << "Database version = " << version << ", LMS binary version = " << LMS_DATABASE_VERSION;
|
||||
LMS_LOG(DB, INFO, "Database version = " << version << ", LMS binary version = " << LMS_DATABASE_VERSION);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LMS_LOG(DB, ERROR) << "Cannot get database version info: " << e.what();
|
||||
LMS_LOG(DB, ERROR, "Cannot get database version info: " << e.what());
|
||||
throw LmsException{ outdatedMsg };
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
|
||||
|
||||
while (version < LMS_DATABASE_VERSION)
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Migrating database from version " << version << " to " << version + 1 << "...";
|
||||
LMS_LOG(DB, INFO, "Migrating database from version " << version << " to " << version + 1 << "...");
|
||||
|
||||
auto itMigrationFunc{ migrationFunctions.find(version) };
|
||||
assert(itMigrationFunc != std::cend(migrationFunctions));
|
||||
@@ -306,7 +306,7 @@ CREATE TABLE IF NOT EXISTS "track_backup" (
|
||||
|
||||
VersionInfo::get(session).modify()->setVersion(++version);
|
||||
|
||||
LMS_LOG(DB, INFO) << "Migration complete to version " << version;
|
||||
LMS_LOG(DB, INFO, "Migration complete to version " << version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "services/database/Session.hpp"
|
||||
#include "services/database/Track.hpp"
|
||||
#include "services/database/User.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "SqlQuery.hpp"
|
||||
#include "EnumSetTraits.hpp"
|
||||
#include "IdTypeTraits.hpp"
|
||||
|
||||
@@ -22,131 +22,123 @@
|
||||
#include <Wt/Dbo/WtSqlTraits.h>
|
||||
|
||||
#include "utils/Path.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "utils/String.hpp"
|
||||
|
||||
#include "services/database/Cluster.hpp"
|
||||
#include "services/database/Session.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
const std::set<std::string> defaultClusterTypeNames =
|
||||
namespace Database
|
||||
{
|
||||
"GENRE",
|
||||
"ALBUMGROUPING",
|
||||
"MOOD",
|
||||
"ALBUMMOOD",
|
||||
};
|
||||
namespace
|
||||
{
|
||||
|
||||
}
|
||||
const std::set<std::string_view> defaultClusterTypeNames =
|
||||
{
|
||||
"GENRE",
|
||||
"ALBUMGROUPING",
|
||||
"MOOD",
|
||||
"ALBUMMOOD",
|
||||
};
|
||||
|
||||
namespace Database {
|
||||
}
|
||||
void ScanSettings::init(Session& session)
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
|
||||
void
|
||||
ScanSettings::init(Session& session)
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
pointer settings{ get(session) };
|
||||
if (settings)
|
||||
return;
|
||||
|
||||
pointer settings {get(session)};
|
||||
if (settings)
|
||||
return;
|
||||
settings = session.getDboSession().add(std::make_unique<ScanSettings>());
|
||||
settings.modify()->setClusterTypes(session, defaultClusterTypeNames);
|
||||
}
|
||||
|
||||
settings = session.getDboSession().add(std::make_unique<ScanSettings>());
|
||||
settings.modify()->setClusterTypes(session, defaultClusterTypeNames );
|
||||
}
|
||||
ScanSettings::pointer ScanSettings::get(Session& session)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
ScanSettings::pointer
|
||||
ScanSettings::get(Session& session)
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
return session.getDboSession().find<ScanSettings>().resultValue();
|
||||
}
|
||||
|
||||
return session.getDboSession().find<ScanSettings>().resultValue();
|
||||
}
|
||||
std::vector<std::filesystem::path> ScanSettings::getAudioFileExtensions() const
|
||||
{
|
||||
const auto extensions{ StringUtils::splitString(_audioFileExtensions, " ") };
|
||||
|
||||
std::vector<std::filesystem::path>
|
||||
ScanSettings::getAudioFileExtensions() const
|
||||
{
|
||||
const auto extensions {StringUtils::splitString(_audioFileExtensions, " ")};
|
||||
std::vector<std::filesystem::path> res(std::cbegin(extensions), std::cend(extensions));
|
||||
std::sort(std::begin(res), std::end(res));
|
||||
res.erase(std::unique(std::begin(res), std::end(res)), std::end(res));
|
||||
|
||||
std::vector<std::filesystem::path> res (std::cbegin(extensions), std::cend(extensions));
|
||||
std::sort(std::begin(res), std::end(res));
|
||||
res.erase(std::unique( std::begin(res), std::end(res)), std::end(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
void ScanSettings::addAudioFileExtension(const std::filesystem::path& ext)
|
||||
{
|
||||
_audioFileExtensions += " " + ext.string();
|
||||
}
|
||||
|
||||
void
|
||||
ScanSettings::addAudioFileExtension(const std::filesystem::path& ext)
|
||||
{
|
||||
_audioFileExtensions += " " + ext.string();
|
||||
}
|
||||
std::vector<ClusterType::pointer> ScanSettings::getClusterTypes() const
|
||||
{
|
||||
return std::vector<ClusterType::pointer>(std::cbegin(_clusterTypes), std::cend(_clusterTypes));
|
||||
}
|
||||
|
||||
std::vector<ClusterType::pointer>
|
||||
ScanSettings::getClusterTypes() const
|
||||
{
|
||||
return std::vector<ClusterType::pointer>(std::cbegin(_clusterTypes), std::cend(_clusterTypes));
|
||||
}
|
||||
void ScanSettings::setMediaDirectory(const std::filesystem::path& p)
|
||||
{
|
||||
_mediaDirectory = StringUtils::stringTrimEnd(p.string(), "/\\");
|
||||
}
|
||||
|
||||
void
|
||||
ScanSettings::setMediaDirectory(const std::filesystem::path& p)
|
||||
{
|
||||
_mediaDirectory = StringUtils::stringTrimEnd(p.string(), "/\\");
|
||||
}
|
||||
template <typename It>
|
||||
std::set<std::string> getNames(It begin, It end)
|
||||
{
|
||||
std::set<std::string> names;
|
||||
std::transform(begin, end, std::inserter(names, std::cbegin(names)),
|
||||
[](const ClusterType::pointer& clusterType)
|
||||
{
|
||||
return clusterType->getName();
|
||||
});
|
||||
|
||||
template <typename It>
|
||||
std::set<std::string> getNames(It begin, It end)
|
||||
{
|
||||
std::set<std::string> names;
|
||||
std::transform(begin, end, std::inserter(names, std::cbegin(names)),
|
||||
[](const ClusterType::pointer& clusterType)
|
||||
{
|
||||
return clusterType->getName();
|
||||
});
|
||||
return names;
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
void ScanSettings::setClusterTypes(Session& session, const std::set<std::string_view>& clusterTypeNames)
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
|
||||
void
|
||||
ScanSettings::setClusterTypes(Session& session, const std::set<std::string>& clusterTypeNames)
|
||||
{
|
||||
session.checkWriteTransaction();
|
||||
bool needRescan{};
|
||||
|
||||
bool needRescan {};
|
||||
// Create any missing cluster type
|
||||
for (const std::string_view clusterTypeName : clusterTypeNames)
|
||||
{
|
||||
ClusterType::pointer clusterType{ ClusterType::find(session, clusterTypeName) };
|
||||
if (!clusterType)
|
||||
{
|
||||
LMS_LOG(DB, INFO, "Creating cluster type " << clusterTypeName);
|
||||
clusterType = session.create<ClusterType>(clusterTypeName);
|
||||
_clusterTypes.insert(getDboPtr(clusterType));
|
||||
|
||||
// Create any missing cluster type
|
||||
for (const std::string& clusterTypeName : clusterTypeNames)
|
||||
{
|
||||
ClusterType::pointer clusterType {ClusterType::find(session, clusterTypeName)};
|
||||
if (!clusterType)
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Creating cluster type " << clusterTypeName;
|
||||
clusterType = session.create<ClusterType>(clusterTypeName);
|
||||
_clusterTypes.insert(getDboPtr(clusterType));
|
||||
needRescan = true;
|
||||
}
|
||||
}
|
||||
|
||||
needRescan = true;
|
||||
}
|
||||
}
|
||||
// Delete no longer existing cluster types
|
||||
for (Wt::Dbo::ptr<ClusterType> clusterType : _clusterTypes)
|
||||
{
|
||||
if (std::none_of(clusterTypeNames.begin(), clusterTypeNames.end(),
|
||||
[clusterType](std::string_view name) { return name == clusterType->getName(); }))
|
||||
{
|
||||
LMS_LOG(DB, INFO, "Deleting cluster type " << clusterType->getName());
|
||||
clusterType.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Delete no longer existing cluster types
|
||||
for (Wt::Dbo::ptr<ClusterType> clusterType : _clusterTypes)
|
||||
{
|
||||
if (std::none_of(clusterTypeNames.begin(), clusterTypeNames.end(),
|
||||
[clusterType](const std::string& name) { return name == clusterType->getName(); }))
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Deleting cluster type " << clusterType->getName();
|
||||
clusterType.remove();
|
||||
}
|
||||
}
|
||||
if (needRescan)
|
||||
_scanVersion += 1;
|
||||
}
|
||||
|
||||
if (needRescan)
|
||||
_scanVersion += 1;
|
||||
}
|
||||
|
||||
void
|
||||
ScanSettings::incScanVersion()
|
||||
{
|
||||
_scanVersion += 1;
|
||||
}
|
||||
void
|
||||
ScanSettings::incScanVersion()
|
||||
{
|
||||
_scanVersion += 1;
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "utils/Exception.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
|
||||
#include "services/database/Artist.hpp"
|
||||
#include "services/database/AuthToken.hpp"
|
||||
@@ -107,20 +107,20 @@ namespace Database
|
||||
|
||||
void Session::prepareTables()
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Preparing tables...";
|
||||
LMS_LOG(DB, INFO, "Preparing tables...");
|
||||
|
||||
// Initial creation case
|
||||
try
|
||||
{
|
||||
_session.createTables();
|
||||
LMS_LOG(DB, INFO) << "Tables created";
|
||||
LMS_LOG(DB, INFO, "Tables created");
|
||||
}
|
||||
catch (Wt::Dbo::Exception& e)
|
||||
{
|
||||
LMS_LOG(DB, DEBUG) << "Cannot create tables: " << e.what();
|
||||
LMS_LOG(DB, DEBUG, "Cannot create tables: " << e.what());
|
||||
if (std::string_view{ e.what() }.find("already exists") == std::string_view::npos)
|
||||
{
|
||||
LMS_LOG(DB, ERROR) << "Cannot create tables: " << e.what();
|
||||
LMS_LOG(DB, ERROR, "Cannot create tables: " << e.what());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -182,22 +182,22 @@ namespace Database
|
||||
|
||||
void Session::analyze()
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Analyzing database...";
|
||||
LMS_LOG(DB, INFO, "Analyzing database...");
|
||||
{
|
||||
auto transaction{ createWriteTransaction() };
|
||||
_session.execute("ANALYZE");
|
||||
}
|
||||
LMS_LOG(DB, INFO) << "Database Analyze complete";
|
||||
LMS_LOG(DB, INFO, "Database Analyze complete");
|
||||
}
|
||||
|
||||
void Session::optimize()
|
||||
{
|
||||
LMS_LOG(DB, INFO) << "Optimizing database...";
|
||||
LMS_LOG(DB, INFO, "Optimizing database...");
|
||||
{
|
||||
auto transaction{ createWriteTransaction() };
|
||||
_session.execute("PRAGMA optimize");
|
||||
}
|
||||
LMS_LOG(DB, INFO) << "Database optimizing complete";
|
||||
LMS_LOG(DB, INFO, "Database optimizing complete");
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "services/database/TrackFeatures.hpp"
|
||||
#include "services/database/Session.hpp"
|
||||
#include "services/database/User.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
|
||||
#include "IdTypeTraits.hpp"
|
||||
#include "SqlQuery.hpp"
|
||||
@@ -536,7 +536,7 @@ namespace Database
|
||||
for (auto artist : track->getArtists({ TrackArtistLinkType::Artist }))
|
||||
os << " - " << artist->getName();
|
||||
for (auto cluster : track->getClusters())
|
||||
os << " {" + cluster->getType()->getName() << "-" << cluster->getName() << "}";
|
||||
os << " {" << cluster->getType()->getName() << "-" << cluster->getName() << "}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "services/database/Session.hpp"
|
||||
#include "services/database/Track.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "IdTypeTraits.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Database {
|
||||
}
|
||||
catch (boost::property_tree::ptree_error& error)
|
||||
{
|
||||
LMS_LOG(DB, ERROR) << "Track " << _track.id() << ": ptree exception: " << error.what();
|
||||
LMS_LOG(DB, ERROR, "Track " << _track.id() << ": ptree exception: " << error.what());
|
||||
res.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
|
||||
#include "services/database/Artist.hpp"
|
||||
#include "services/database/Cluster.hpp"
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "services/database/Release.hpp"
|
||||
#include "services/database/Session.hpp"
|
||||
#include "services/database/Track.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/ILogger.hpp"
|
||||
#include "IdTypeTraits.hpp"
|
||||
#include "StringViewTraits.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace Database {
|
||||
static void remove(Session& session, const std::string& name);
|
||||
|
||||
// Accessors
|
||||
const std::string& getName() const { return _name; }
|
||||
std::string_view getName() const { return _name; }
|
||||
std::vector<Cluster::pointer> getClusters() const;
|
||||
Cluster::pointer getCluster(const std::string& name) const;
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace Database {
|
||||
private:
|
||||
friend class Session;
|
||||
ClusterType(std::string_view name);
|
||||
static pointer create(Session& session, const std::string& name);
|
||||
static pointer create(Session& session, std::string_view name);
|
||||
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <Wt/Dbo/Dbo.h>
|
||||
@@ -74,7 +76,7 @@ namespace Database {
|
||||
void setMediaDirectory(const std::filesystem::path& p);
|
||||
void setUpdateStartTime(Wt::WTime t) { _startTime = t; }
|
||||
void setUpdatePeriod(UpdatePeriod p) { _updatePeriod = p; }
|
||||
void setClusterTypes(Session& session, const std::set<std::string>& clusterTypeNames);
|
||||
void setClusterTypes(Session& session, const std::set<std::string_view>& clusterTypeNames);
|
||||
void setSimilarityEngineType(SimilarityEngineType type) { _similarityEngineType = type; }
|
||||
void incScanVersion();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user