Core/Mail: Load mails at login instead of on demand when queried by packets (logging in always sends one of the packets that cause mail loading anyway)
This commit is contained in:
1 parent
adb7e4dba8
commit
80e4effba5
8 files changed
+49
-105
No files matched your search
@@ -266,7 +266,6 @@ Player::Player(WorldSession* session): Unit(true)
|
||||
_restFlagMask = 0;
|
||||
////////////////////Rest System/////////////////////
|
||||
|
||||
m_mailsLoaded = false;
|
||||
m_mailsUpdated = false;
|
||||
unReadMails = 0;
|
||||
m_nextMailDelivereTime = 0;
|
||||
@@ -17631,7 +17630,7 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder* holder)
|
||||
_LoadActions(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_ACTIONS));
|
||||
|
||||
// unread mails and next delivery time, actual mails not loaded
|
||||
_LoadMailInit(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MAIL_COUNT), holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MAIL_DATE));
|
||||
_LoadMail(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MAILS), holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_MAIL_ITEMS));
|
||||
|
||||
m_social = sSocialMgr->LoadFromDB(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_SOCIAL_LIST), GetGUID());
|
||||
|
||||
@@ -18365,34 +18364,17 @@ Item* Player::_LoadMailedItem(ObjectGuid const& playerGuid, Player* player, uint
|
||||
return item;
|
||||
}
|
||||
|
||||
void Player::_LoadMailInit(PreparedQueryResult resultUnread, PreparedQueryResult resultDelivery)
|
||||
{
|
||||
//set a count of unread mails
|
||||
//QueryResult* resultMails = CharacterDatabase.PQuery("SELECT COUNT(id) FROM mail WHERE receiver = '%u' AND (checked & 1)=0 AND deliver_time <= '" UI64FMTD "'", GUID_LOPART(playerGuid), (uint64)cTime);
|
||||
if (resultUnread)
|
||||
unReadMails = uint8((*resultUnread)[0].GetUInt64());
|
||||
|
||||
// store nearest delivery time (it > 0 and if it < current then at next player update SendNewMaill will be called)
|
||||
//resultMails = CharacterDatabase.PQuery("SELECT MIN(deliver_time) FROM mail WHERE receiver = '%u' AND (checked & 1)=0", GUID_LOPART(playerGuid));
|
||||
if (resultDelivery)
|
||||
m_nextMailDelivereTime = time_t((*resultDelivery)[0].GetUInt32());
|
||||
}
|
||||
|
||||
void Player::_LoadMail()
|
||||
void Player::_LoadMail(PreparedQueryResult mailsResult, PreparedQueryResult mailItemsResult)
|
||||
{
|
||||
m_mail.clear();
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAIL);
|
||||
stmt->setUInt32(0, GetGUID().GetCounter());
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
|
||||
std::unordered_map<uint32, Mail*> mailById;
|
||||
|
||||
if (result)
|
||||
if (mailsResult)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
Field* fields = mailsResult->Fetch();
|
||||
Mail* m = new Mail;
|
||||
|
||||
m->messageID = fields[0].GetUInt32();
|
||||
@@ -18419,24 +18401,20 @@ void Player::_LoadMail()
|
||||
m_mail.push_back(m);
|
||||
mailById[m->messageID] = m;
|
||||
}
|
||||
while (result->NextRow());
|
||||
while (mailsResult->NextRow());
|
||||
}
|
||||
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_MAILITEMS);
|
||||
stmt->setUInt32(0, GetGUID().GetCounter());
|
||||
result = CharacterDatabase.Query(stmt);
|
||||
|
||||
if (result)
|
||||
if (mailItemsResult)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
Field* fields = mailItemsResult->Fetch();
|
||||
uint32 mailId = fields[14].GetUInt32();
|
||||
_LoadMailedItem(GetGUID(), this, mailId, mailById[mailId], fields);
|
||||
} while (result->NextRow());
|
||||
} while (mailItemsResult->NextRow());
|
||||
}
|
||||
|
||||
m_mailsLoaded = true;
|
||||
UpdateNextMailTimeAndUnreads();
|
||||
}
|
||||
|
||||
void Player::LoadPet()
|
||||
@@ -20134,9 +20112,6 @@ void Player::_SaveCUFProfiles(CharacterDatabaseTransaction& trans)
|
||||
|
||||
void Player::_SaveMail(CharacterDatabaseTransaction& trans)
|
||||
{
|
||||
if (!m_mailsLoaded)
|
||||
return;
|
||||
|
||||
CharacterDatabasePreparedStatement* stmt;
|
||||
|
||||
for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
|
||||
|
||||
Reference in new issue
Block a user