Made STB the default image manipulation library to reduce memory usage (GraphicsMagick can still be selected). closes #93
This commit is contained in:
@@ -32,14 +32,14 @@ Cluster::Cluster()
|
||||
{
|
||||
}
|
||||
|
||||
Cluster::Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name)
|
||||
: _name(std::string(name, 0, _maxNameLength)),
|
||||
_clusterType(type)
|
||||
Cluster::Cluster(Wt::Dbo::ptr<ClusterType> type, std::string_view name)
|
||||
: _name(std::string {name, 0, _maxNameLength}),
|
||||
_clusterType {type}
|
||||
{
|
||||
}
|
||||
|
||||
Cluster::pointer
|
||||
Cluster::create(Session& session, Wt::Dbo::ptr<ClusterType> type, std::string name)
|
||||
Cluster::create(Session& session, Wt::Dbo::ptr<ClusterType> type, std::string_view name)
|
||||
{
|
||||
session.checkUniqueLocked();
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <Wt/Dbo/FixedSqlConnectionPool.h>
|
||||
#include <Wt/Dbo/backend/Sqlite3.h>
|
||||
|
||||
#include "database/Session.hpp"
|
||||
#include "database/User.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
@@ -57,6 +58,24 @@ Db::executeSql(const std::string& sql)
|
||||
connection->executeSql(sql);
|
||||
}
|
||||
|
||||
Session&
|
||||
Db::getTLSSession()
|
||||
{
|
||||
static thread_local Session* tlsSession {};
|
||||
|
||||
if (!tlsSession)
|
||||
{
|
||||
auto newSession {std::make_unique<Session>(*this)};
|
||||
tlsSession = newSession.get();
|
||||
|
||||
{
|
||||
std::scoped_lock lock {_tlsSessionsMutex};
|
||||
_tlsSessions.push_back(std::move(newSession));
|
||||
}
|
||||
}
|
||||
|
||||
return *tlsSession;
|
||||
}
|
||||
|
||||
Db::ScopedConnection::ScopedConnection(Wt::Dbo::SqlConnectionPool& pool)
|
||||
: _connectionPool {pool}
|
||||
|
||||
@@ -362,13 +362,13 @@ Session::checkSharedLocked()
|
||||
UniqueTransaction
|
||||
Session::createUniqueTransaction()
|
||||
{
|
||||
return UniqueTransaction{_db.getMutex(), _session};
|
||||
return UniqueTransaction {_db.getMutex(), _session};
|
||||
}
|
||||
|
||||
SharedTransaction
|
||||
Session::createSharedTransaction()
|
||||
{
|
||||
return SharedTransaction{_db.getMutex(), _session};
|
||||
return SharedTransaction {_db.getMutex(), _session};
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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/SessionPool.hpp"
|
||||
|
||||
|
||||
#include "database/Session.hpp"
|
||||
#include "utils/Exception.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
SessionPool::SessionPool(Db& database, std::size_t maxSessionCount)
|
||||
: _db {database},
|
||||
_maxSessionCount {maxSessionCount}
|
||||
{
|
||||
}
|
||||
|
||||
Session&
|
||||
SessionPool::acquireSession()
|
||||
{
|
||||
std::scoped_lock lock {_mutex};
|
||||
|
||||
if (_freeSessions.empty())
|
||||
{
|
||||
if (_acquiredSessions.size() == _maxSessionCount)
|
||||
throw LmsException {"Too many database sessions!"};
|
||||
|
||||
_freeSessions.emplace_back(std::make_unique<Session>(_db));
|
||||
}
|
||||
|
||||
std::unique_ptr<Session> session {std::move(_freeSessions.back())};
|
||||
_freeSessions.pop_back();
|
||||
_acquiredSessions.push_back(std::move(session));
|
||||
|
||||
return *_acquiredSessions.back().get();
|
||||
}
|
||||
|
||||
void
|
||||
SessionPool::releaseSession(Session& sessionToRelease)
|
||||
{
|
||||
std::scoped_lock lock {_mutex};
|
||||
|
||||
auto it {std::find_if(std::begin(_acquiredSessions), std::end(_acquiredSessions), [&](const std::unique_ptr<Session>& session) { return session.get() == &sessionToRelease; })};
|
||||
if (it == std::end(_acquiredSessions))
|
||||
throw LmsException {"Unknown released Session!"};
|
||||
|
||||
std::unique_ptr<Session> session {std::move(*it)};
|
||||
_acquiredSessions.erase(it);
|
||||
_freeSessions.push_back(std::move(session));
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
Reference in New Issue
Block a user