Fixed regression on recommendation engine
This commit is contained in:
@@ -43,6 +43,13 @@ Db::Db(const std::filesystem::path& dbPath)
|
||||
_connectionPool = std::move(connectionPool);
|
||||
}
|
||||
|
||||
Db::~Db()
|
||||
{
|
||||
LMS_LOG(DB, DEBUG) << "Optimizing db...";
|
||||
executeSql("pragma optimize");
|
||||
LMS_LOG(DB, DEBUG) << "Optimizing db DONE";
|
||||
}
|
||||
|
||||
void
|
||||
Db::executeSql(const std::string& sql)
|
||||
{
|
||||
|
||||
@@ -32,6 +32,12 @@ class Db
|
||||
public:
|
||||
|
||||
Db(const std::filesystem::path& dbPath);
|
||||
~Db();
|
||||
|
||||
Db(const Db&) = delete;
|
||||
Db(Db&&) = delete;
|
||||
Db& operator=(const Db&) = delete;
|
||||
Db& operator=(Db&&) = delete;
|
||||
|
||||
private:
|
||||
friend class Session;
|
||||
|
||||
@@ -38,6 +38,12 @@ createEngine(Database::Db& db)
|
||||
Engine::Engine(Database::Db& db)
|
||||
: _dbSession {db}
|
||||
{
|
||||
start();
|
||||
}
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -45,9 +51,6 @@ Engine::start()
|
||||
{
|
||||
assert(!_running);
|
||||
_running = true;
|
||||
|
||||
requestReloadInternal(false);
|
||||
|
||||
_ioService.start();
|
||||
}
|
||||
|
||||
@@ -62,6 +65,12 @@ Engine::stop()
|
||||
_ioService.stop();
|
||||
}
|
||||
|
||||
void
|
||||
Engine::requestLoad()
|
||||
{
|
||||
requestReloadInternal(false);
|
||||
}
|
||||
|
||||
void
|
||||
Engine::requestReload()
|
||||
{
|
||||
@@ -254,7 +263,7 @@ void
|
||||
Engine::cancelPendingClassifiers()
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock {_classifiersMutex};
|
||||
|
||||
|
||||
for (IClassifier* classifier : _pendingClassifiers)
|
||||
classifier->requestCancelInit();
|
||||
}
|
||||
|
||||
@@ -35,12 +35,19 @@ namespace Recommendation
|
||||
{
|
||||
public:
|
||||
Engine(Database::Db& db);
|
||||
~Engine();
|
||||
|
||||
Engine(const Engine&) = delete;
|
||||
Engine(Engine&&) = delete;
|
||||
Engine& operator=(const Engine&) = delete;
|
||||
Engine& operator=(Engine&&) = delete;
|
||||
|
||||
private:
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
void requestLoad() override;
|
||||
void requestReload() override;
|
||||
Wt::Signal<>& reloaded() override { return _sigReloaded; }
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ namespace Recommendation
|
||||
public:
|
||||
virtual ~IEngine() = default;
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void requestLoad() = 0;
|
||||
|
||||
virtual void requestReload() = 0;
|
||||
virtual Wt::Signal<>& reloaded() = 0;
|
||||
|
||||
@@ -254,6 +254,8 @@ MediaScanner::MediaScanner(Database::Db& db)
|
||||
_ioService.setThreadCount(1);
|
||||
|
||||
refreshScanSettings();
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
MediaScanner::~MediaScanner()
|
||||
|
||||
@@ -50,8 +50,6 @@ class MediaScanner : public IMediaScanner
|
||||
MediaScanner& operator=(const MediaScanner&) = delete;
|
||||
MediaScanner& operator=(MediaScanner&&) = delete;
|
||||
|
||||
void start() override;
|
||||
void stop() override;
|
||||
void requestReload() override;
|
||||
void requestImmediateScan(bool force) override;
|
||||
|
||||
@@ -64,6 +62,9 @@ class MediaScanner : public IMediaScanner
|
||||
|
||||
private:
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
// Job handling
|
||||
void scheduleNextScan();
|
||||
void scheduleScan(bool force, const Wt::WDateTime& dateTime = {});
|
||||
|
||||
@@ -38,14 +38,10 @@ class IMediaScanner
|
||||
public:
|
||||
virtual ~IMediaScanner() = default;
|
||||
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
// Async requests
|
||||
virtual void requestReload() = 0;
|
||||
virtual void requestImmediateScan(bool force) = 0;
|
||||
|
||||
|
||||
enum class State
|
||||
{
|
||||
NotScheduled,
|
||||
|
||||
@@ -171,6 +171,7 @@ int main(int argc, char* argv[])
|
||||
Service<CoverArt::IGrabber> coverArtService {CoverArt::createGrabber(argv[0])};
|
||||
coverArtService->setDefaultCover(server.appRoot() + "/images/unknown-cover.jpg");
|
||||
Service<Recommendation::IEngine> recommendationEngineService {Recommendation::createEngine(database)};
|
||||
recommendationEngineService->requestLoad();
|
||||
Service<Scanner::IMediaScanner> mediaScannerService {Scanner::createMediaScanner(database)};
|
||||
|
||||
mediaScannerService->scanComplete().connect([&]()
|
||||
|
||||
@@ -6,6 +6,7 @@ add_executable(lms-recommendation
|
||||
target_link_libraries(lms-recommendation PRIVATE
|
||||
lmsdatabase
|
||||
lmsrecommendation
|
||||
Boost::program_options
|
||||
)
|
||||
|
||||
install(TARGETS lms-recommendation DESTINATION bin)
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include <stdexcept>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Cluster.hpp"
|
||||
#include "database/Db.hpp"
|
||||
@@ -130,14 +132,30 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
namespace po = boost::program_options;
|
||||
|
||||
// log to stdout
|
||||
Service<Logger> logger {std::make_unique<StreamLogger>(std::cout)};
|
||||
|
||||
std::filesystem::path configFilePath {"/etc/lms.conf"};
|
||||
if (argc >= 2)
|
||||
configFilePath = std::string(argv[1], 0, 256);
|
||||
po::options_description desc{"Allowed options"};
|
||||
desc.add_options()
|
||||
("help,h", "print usage message")
|
||||
("conf,c", po::value<std::string>()->default_value("/etc/lms.conf"), "LMS config file")
|
||||
("artists,a", "Display recommendation for artists")
|
||||
("releases,r", "Display recommendation for releases")
|
||||
("tracks,t", "Display recommendation for tracks")
|
||||
;
|
||||
|
||||
Service<IConfig> config {createConfig(configFilePath)};
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
std::cout << desc << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Service<IConfig> config {createConfig(vm["conf"].as<std::string>())};
|
||||
|
||||
Database::Db db {config->getPath("working-dir") / "lms.db"};
|
||||
Database::Session session {db};
|
||||
@@ -153,17 +171,20 @@ int main(int argc, char *argv[])
|
||||
sem.notify();
|
||||
});
|
||||
|
||||
engine->start();
|
||||
engine->requestLoad();
|
||||
|
||||
std::cout << "Waiting for the recommendation engine to be loaded..." << std::endl;
|
||||
sem.wait();
|
||||
std::cout << "Recommendation engine loaded!" << std::endl;
|
||||
|
||||
dumpTracksRecommendation(db, *engine);
|
||||
dumpReleasesRecommendation(db, *engine);
|
||||
dumpArtistsRecommendation(db, *engine);
|
||||
if (vm.count("tracks"))
|
||||
dumpTracksRecommendation(db, *engine);
|
||||
|
||||
engine->stop();
|
||||
if (vm.count("releases"))
|
||||
dumpReleasesRecommendation(db, *engine);
|
||||
|
||||
if (vm.count("artists"))
|
||||
dumpArtistsRecommendation(db, *engine);
|
||||
}
|
||||
catch( std::exception& e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user