[8822] one big insert for character_aura and _SaveSpellCooldowns

this is much faster than many multiple inserts..

code is partly stolen from AchievementMgr inserts (:
This commit is contained in:
balrok 2009-11-14 08:46:29 -05:00
parent 6199396b69
commit 31a2996374
2 changed files with 39 additions and 5 deletions

View file

@ -3469,6 +3469,10 @@ void Player::_SaveSpellCooldowns()
time_t curTime = time(NULL);
time_t infTime = curTime + infinityCooldownDelayCheck;
/* copied following sql-code partly from achievementmgr */
bool first_round = true;
std::ostringstream ss;
// remove outdated and save active
for(SpellCooldowns::iterator itr = m_spellCooldowns.begin();itr != m_spellCooldowns.end();)
{
@ -3476,12 +3480,24 @@ void Player::_SaveSpellCooldowns()
m_spellCooldowns.erase(itr++);
else if(itr->second.end <= infTime) // not save locked cooldowns, it will be reset or set at reload
{
CharacterDatabase.PExecute("INSERT INTO character_spell_cooldown (guid,spell,item,time) VALUES ('%u', '%u', '%u', '" UI64FMTD "')", GetGUIDLow(), itr->first, itr->second.itemid, uint64(itr->second.end));
if (first_round)
{
ss << "INSERT INTO character_spell_cooldown (guid,spell,item,time) VALUES ";
first_round = false;
}
// next new/changed record prefix
else
ss << ", ";
ss << "(" << GetGUIDLow() << "," << itr->first << "," << itr->second.itemid << "," << uint64(itr->second.end) << ")";
++itr;
}
else
++itr;
}
// if something changed execute
if (!first_round)
CharacterDatabase.Execute( ss.str().c_str() );
}
uint32 Player::resetTalentsCost() const
@ -15792,6 +15808,9 @@ void Player::_SaveAuras()
spellEffectPair lastEffectPair = auras.begin()->first;
uint32 stackCounter = 1;
/* copied following sql-code partly from achievementmgr */
bool first_round = true;
std::ostringstream ss;
for(AuraMap::const_iterator itr = auras.begin(); ; ++itr)
{
if(itr == auras.end() || lastEffectPair != itr->first)
@ -15804,9 +15823,20 @@ void Player::_SaveAuras()
//do not save single target auras (unless they were cast by the player)
if (!itr2->second->IsPassive() && (itr2->second->GetCasterGUID() == GetGUID() || !itr2->second->IsSingleTarget()))
{
CharacterDatabase.PExecute("INSERT INTO character_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges) "
"VALUES ('%u', '" UI64FMTD "' ,'%u', '%u', '%u', '%d', '%d', '%d', '%d')",
GetGUIDLow(), itr2->second->GetCasterGUID(), (uint32)itr2->second->GetId(), (uint32)itr2->second->GetEffIndex(), stackCounter, itr2->second->GetModifier()->m_amount,int(itr2->second->GetAuraMaxDuration()),int(itr2->second->GetAuraDuration()),int(itr2->second->GetAuraCharges()));
if (first_round)
{
ss << "INSERT INTO character_aura (guid,caster_guid,spell,effect_index,stackcount,amount,maxduration,remaintime,remaincharges)VALUES ";
first_round = false;
}
// next new/changed record prefix
else
ss << ", ";
ss << "("<< GetGUIDLow() << "," << itr2->second->GetCasterGUID() << ","
<< (uint32)itr2->second->GetId() << "," << (uint32)itr2->second->GetEffIndex() << ","
<< stackCounter << "," << itr2->second->GetModifier()->m_amount << ","
<<int(itr2->second->GetAuraMaxDuration()) << "," << int(itr2->second->GetAuraDuration()) << ","
<< int(itr2->second->GetAuraCharges()) << ")";
}
if(itr == auras.end())
@ -15821,6 +15851,10 @@ void Player::_SaveAuras()
stackCounter = 1;
}
}
// if something changed execute
if (!first_round)
CharacterDatabase.Execute( ss.str().c_str() );
}
void Player::_SaveInventory()