Remedy connection type query at every login (#2298)

Fix #2285
This change adds an internal counter for each tcp/web socket connection
that the server makes and queries the stored memory count at login
rather than the previous way that quired the database during each login.
Each login that quired the DB put a significant load on the server as
the user base grew.
This commit is contained in:
woogerboy21
2016-12-07 01:35:35 -05:00
committed by GitHub
parent a6f1f4c01d
commit f86b9e0be7
3 changed files with 19 additions and 4 deletions

View File

@@ -38,7 +38,7 @@
#include <QDebug>
Server::Server(QObject *parent)
: QObject(parent), nextLocalGameId(0)
: QObject(parent), nextLocalGameId(0), tcpUserCount(0), webSocketUserCount(0)
{
qRegisterMetaType<ServerInfo_Ban>("ServerInfo_Ban");
qRegisterMetaType<ServerInfo_Game>("ServerInfo_Game");
@@ -202,12 +202,25 @@ Server_AbstractUserInterface *Server::findUser(const QString &userName) const
void Server::addClient(Server_ProtocolHandler *client)
{
if (client->getConnectionType() == "tcp")
tcpUserCount++;
if (client->getConnectionType() == "websocket")
webSocketUserCount++;
QWriteLocker locker(&clientsLock);
clients << client;
}
void Server::removeClient(Server_ProtocolHandler *client)
{
if (client->getConnectionType() == "tcp")
tcpUserCount--;
if (client->getConnectionType() == "websocket")
webSocketUserCount--;
QWriteLocker locker(&clientsLock);
clients.removeAt(clients.indexOf(client));
ServerInfo_User *data = client->getUserInfo();