diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-10-30 10:00:32 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-10-30 10:00:32 +0200 |
commit | a84572c5449c74d9107a9c725a5feb32e439843e (patch) | |
tree | 180f2b3b0c1bb0ae17f099849fba4d7cde86f304 /src/account-server/serverhandler.cpp | |
parent | e411f5ce26d6175affab0288e97a6ead8990ee61 (diff) | |
download | manaserv-a84572c5449c74d9107a9c725a5feb32e439843e.tar.gz manaserv-a84572c5449c74d9107a9c725a5feb32e439843e.tar.bz2 manaserv-a84572c5449c74d9107a9c725a5feb32e439843e.tar.xz manaserv-a84572c5449c74d9107a9c725a5feb32e439843e.zip |
Use a transaction when handling a GAMSG_PLAYER_SYNC message
This message can contain a lot of small database updates, which at least
on my system are way more efficient when performed in a transaction (now
it takes no more than 1 second vs. about 14 seconds before). Not saying
this is normal, my guess is that it's due to using full partition
encryption.
I've also prevented the thing from entering an infinite loop in the case
of a wrong message, and corrected some variable names.
Diffstat (limited to 'src/account-server/serverhandler.cpp')
-rw-r--r-- | src/account-server/serverhandler.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/account-server/serverhandler.cpp b/src/account-server/serverhandler.cpp index 9a263175..9ca9e281 100644 --- a/src/account-server/serverhandler.cpp +++ b/src/account-server/serverhandler.cpp @@ -552,18 +552,21 @@ void GameServerHandler::sendPartyChange(Character *ptr, int partyId) void GameServerHandler::syncDatabase(MessageIn &msg) { + // It is safe to perform the following updates in a transaction + storage->database()->beginTransaction(); + int msgType = msg.readByte(); - while (msgType != SYNC_END_OF_BUFFER) + while (msgType != SYNC_END_OF_BUFFER && msg.getUnreadLength() > 0) { switch (msgType) { case SYNC_CHARACTER_POINTS: { LOG_DEBUG("received SYNC_CHARACTER_POINTS"); - int CharId = msg.readLong(); - int CharPoints = msg.readLong(); - int CorrPoints = msg.readLong(); - storage->updateCharacterPoints(CharId, CharPoints, CorrPoints); + int charId = msg.readLong(); + int charPoints = msg.readLong(); + int corrPoints = msg.readLong(); + storage->updateCharacterPoints(charId, charPoints, corrPoints); } break; case SYNC_CHARACTER_ATTRIBUTE: @@ -579,23 +582,25 @@ void GameServerHandler::syncDatabase(MessageIn &msg) case SYNC_CHARACTER_SKILL: { LOG_DEBUG("received SYNC_CHARACTER_SKILL"); - int CharId = msg.readLong(); - int SkillId = msg.readByte(); - int SkillValue = msg.readLong(); - storage->updateExperience(CharId, SkillId, SkillValue); + int charId = msg.readLong(); + int skillId = msg.readByte(); + int skillValue = msg.readLong(); + storage->updateExperience(charId, skillId, skillValue); } break; case SYNC_ONLINE_STATUS: { LOG_DEBUG("received SYNC_ONLINE_STATUS"); - int CharId = msg.readLong(); + int charId = msg.readLong(); bool online; msg.readByte() == 0x00 ? online = false : online = true; - storage->setOnlineStatus(CharId, online); + storage->setOnlineStatus(charId, online); } } // read next message type from buffer msgType = msg.readByte(); } + + storage->database()->commitTransaction(); } |