Core/Mailsystem: Optimized returning and deleting old mails, will no longer take minutes when starting using old character db
This commit is contained in:
@@ -5446,12 +5446,29 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
|
||||
PreparedQueryResult result = CharacterDatabase.Query(stmt);
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString(">> No expired mails found or DB table `mail` is empty.");
|
||||
sLog->outString(">> No expired mails found.");
|
||||
sLog->outString();
|
||||
return; // any mails need to be returned or deleted
|
||||
}
|
||||
|
||||
uint32 count = 0;
|
||||
std::map<uint32 /*messageId*/, MailItemInfoVec> itemsCache;
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_EXPIRED_MAIL_ITEMS);
|
||||
stmt->setUInt64(0, basetime);
|
||||
if (PreparedQueryResult items = CharacterDatabase.Query(stmt))
|
||||
{
|
||||
MailItemInfo item;
|
||||
do
|
||||
{
|
||||
Field* fields = items->Fetch();
|
||||
item.item_guid = fields[0].GetUInt32();
|
||||
item.item_template = fields[1].GetUInt32();
|
||||
uint32 mailId = fields[2].GetUInt32();
|
||||
itemsCache[mailId].push_back(item);
|
||||
} while (items->NextRow());
|
||||
}
|
||||
|
||||
uint32 deletedCount = 0;
|
||||
uint32 returnedCount = 0;
|
||||
do
|
||||
{
|
||||
|
||||
@@ -5482,21 +5499,9 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
|
||||
// Delete or return mail
|
||||
if (has_items)
|
||||
{
|
||||
stmt = CharacterDatabase.GetPreparedStatement(CHAR_GET_MAIL_ITEM_LITE);
|
||||
stmt->setUInt32(0, m->messageID);
|
||||
if (PreparedQueryResult resultItems = CharacterDatabase.Query(stmt))
|
||||
{
|
||||
do
|
||||
{
|
||||
Field *fields2 = resultItems->Fetch();
|
||||
// read items from cache
|
||||
m->items.swap(itemsCache[m->messageID]);
|
||||
|
||||
uint32 item_guid_low = fields2[0].GetUInt32();
|
||||
uint32 item_template = fields2[1].GetUInt32();
|
||||
|
||||
m->AddItem(item_guid_low, item_template);
|
||||
}
|
||||
while (resultItems->NextRow());
|
||||
}
|
||||
// if it is mail from non-player, or if it's already return mail, it shouldn't be returned, but deleted
|
||||
if (m->messageType != MAIL_NORMAL || (m->checked & (MAIL_CHECK_MASK_COD_PAYMENT | MAIL_CHECK_MASK_RETURNED)))
|
||||
{
|
||||
@@ -5533,6 +5538,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
delete m;
|
||||
++returnedCount;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -5541,11 +5547,11 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
|
||||
stmt->setUInt32(0, m->messageID);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
delete m;
|
||||
++count;
|
||||
++deletedCount;
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %u mails in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString(">> Processed %u expired mails: %u deleted and %u returned in %u ms", deletedCount + returnedCount, deletedCount, returnedCount, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user