Fixed 'remember me' login option for several LMS instances on the same host, fixes #867

This commit is contained in:
emeric
2026-07-17 22:12:07 +02:00
parent 735c170a44
commit b6df7ae120
11 changed files with 178 additions and 16 deletions
+1
View File
@@ -24,6 +24,7 @@ add_library(lmsdatabase STATIC
impl/objects/RatedTrack.cpp
impl/objects/Release.cpp
impl/objects/ScanSettings.cpp
impl/objects/ServerInfo.cpp
impl/objects/StarredArtist.cpp
impl/objects/StarredRelease.cpp
impl/objects/StarredTrack.cpp
+12 -1
View File
@@ -36,7 +36,7 @@ namespace lms::db
{
namespace
{
static constexpr Version LMS_DATABASE_VERSION{ 109 };
static constexpr Version LMS_DATABASE_VERSION{ 110 };
}
VersionInfo::VersionInfo()
@@ -1956,6 +1956,16 @@ CREATE TABLE IF NOT EXISTS "track_movement" (
utils::executeCommand(*session.getDboSession(), "UPDATE scan_settings SET audio_scan_version = audio_scan_version + 1");
}
void migrateFromV109(Session& session)
{
utils::executeCommand(*session.getDboSession(), R"(
CREATE TABLE IF NOT EXISTS "server_info" (
"id" integer primary key autoincrement,
"version" integer not null,
"instance_id" blob not null
))");
}
bool doDbMigration(Session& session)
{
constexpr std::string_view outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
@@ -2041,6 +2051,7 @@ CREATE TABLE IF NOT EXISTS "track_movement" (
{ 106, migrateFromV106 },
{ 107, migrateFromV107 },
{ 108, migrateFromV108 },
{ 109, migrateFromV109 },
};
LMS_SCOPED_TRACE_OVERVIEW("Database", "Migration");
+9
View File
@@ -49,6 +49,7 @@
#include "database/objects/Release.hpp"
#include "database/objects/ReleaseArtistLink.hpp"
#include "database/objects/ScanSettings.hpp"
#include "database/objects/ServerInfo.hpp"
#include "database/objects/StarredArtist.hpp"
#include "database/objects/StarredRelease.hpp"
#include "database/objects/StarredTrack.hpp"
@@ -125,6 +126,7 @@ namespace lms::db
_session.mapClass<UIState>("ui_state");
_session.mapClass<Work>("work");
_session.mapClass<User>("user");
_session.mapClass<ServerInfo>("server_info");
_session.mapClass<VersionInfo>("version_info");
}
@@ -191,6 +193,13 @@ namespace lms::db
create<ScanSettings>().modify()->setRecommendationEngineType(defaultRecommendationEngineType);
}
void Session::createServerInfoIfNeeded()
{
auto uniqueTransaction{ createWriteTransaction() };
ServerInfo::getOrCreate(*this);
}
void Session::createIndexesIfNeeded()
{
LMS_SCOPED_TRACE_OVERVIEW("Database", "IndexCreation");
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2026 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/objects/ServerInfo.hpp"
#include <Wt/Dbo/Impl.h>
#include <Wt/Dbo/WtSqlTraits.h>
#include "database/Session.hpp"
#include "Utils.hpp"
#include "traits/UUIDTraits.hpp"
DBO_INSTANTIATE_TEMPLATES(lms::db::ServerInfo)
namespace lms::db
{
ServerInfo::ServerInfo(core::UUID instanceId)
: _instanceId{ instanceId }
{
}
ServerInfo::pointer ServerInfo::getOrCreate(Session& session)
{
session.checkWriteTransaction();
pointer serverInfo{ utils::fetchQuerySingleResult(session.getDboSession()->find<ServerInfo>()) };
if (!serverInfo)
return session.getDboSession()->add(std::unique_ptr<ServerInfo>{ new ServerInfo{ core::UUID::generate() } });
return serverInfo;
}
ServerInfo::pointer ServerInfo::get(Session& session)
{
session.checkReadTransaction();
return utils::fetchQuerySingleResult(session.getDboSession()->find<ServerInfo>());
}
} // namespace lms::db
@@ -60,6 +60,7 @@ namespace lms::db
void prepareTablesIfNeeded(); // need to run only once at startup
bool migrateSchemaIfNeeded(); // returns true if migration was performed
void createScanSettingsIfNeeded(RecommendationEngineType defaultRecommendationEngineType = RecommendationEngineType::Clusters);
void createServerInfoIfNeeded();
void createIndexesIfNeeded();
void vacuumIfNeeded();
void vacuum();
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2026 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/>.
*/
#pragma once
#include <Wt/Dbo/Field.h>
#include "core/UUID.hpp"
namespace lms::db
{
class Session;
// Singleton row holding server-level metadata (not tied to any particular schema version)
class ServerInfo
{
public:
using pointer = Wt::Dbo::ptr<ServerInfo>;
ServerInfo() = default;
static pointer getOrCreate(Session& session);
static pointer get(Session& session);
core::UUID getInstanceId() const { return _instanceId; }
template<class Action>
void persist(Action& a)
{
Wt::Dbo::field(a, _instanceId, "instance_id");
}
private:
explicit ServerInfo(core::UUID instanceId);
core::UUID _instanceId;
};
} // namespace lms::db
+3
View File
@@ -37,6 +37,7 @@
#include "database/objects/RatedTrack.hpp"
#include "database/objects/ReleaseArtistLink.hpp"
#include "database/objects/ScanSettings.hpp"
#include "database/objects/ServerInfo.hpp"
#include "database/objects/StarredArtist.hpp"
#include "database/objects/StarredRelease.hpp"
#include "database/objects/StarredTrack.hpp"
@@ -345,6 +346,7 @@ VALUES
// Now perform full migration
db.getTLSSession().migrateSchemaIfNeeded();
db.getTLSSession().createScanSettingsIfNeeded();
db.getTLSSession().createServerInfoIfNeeded();
// Now perform some dummy finds to ensure all fields are correctly mapped
{
@@ -374,6 +376,7 @@ VALUES
EXPECT_FALSE(ReleaseArtistLink::find(session, ReleaseArtistLinkId{}));
EXPECT_FALSE(ReleaseType::find(session, ReleaseTypeId{}));
EXPECT_FALSE(ScanSettings::find(session, ScanSettingsId{}));
EXPECT_NE(ServerInfo::get(session)->getInstanceId(), core::UUID{});
EXPECT_FALSE(StarredArtist::find(session, StarredArtistId{}));
EXPECT_FALSE(StarredRelease::find(session, StarredReleaseId{}));
EXPECT_FALSE(StarredTrack::find(session, StarredTrackId{}));