Skip to content

Commit

Permalink
Serialize groups and group_member queries.
Browse files Browse the repository at this point in the history
Thanks to Chero.
  • Loading branch information
ratkosrb committed Sep 14, 2024
1 parent 1657fe8 commit 2aae996
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/game/Group/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool Group::Create(ObjectGuid guid, char const* name)
Player::ConvertInstancesToGroup(leader, this, guid);

// store group in database
CharacterDatabase.BeginTransaction();
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("DELETE FROM `groups` WHERE `group_id` ='%u'", m_Id);
CharacterDatabase.PExecute("DELETE FROM `group_member` WHERE `group_id` ='%u'", m_Id);

Expand All @@ -154,14 +154,12 @@ bool Group::Create(ObjectGuid guid, char const* name)
m_targetIcons[4].GetRawValue(), m_targetIcons[5].GetRawValue(),
m_targetIcons[6].GetRawValue(), m_targetIcons[7].GetRawValue(),
isRaidGroup());
CharacterDatabase.CommitTransaction();
}

if (!AddMember(guid, name))
return false;

if (!isBGGroup())
CharacterDatabase.CommitTransaction();

_updateLeaderFlag();

return true;
Expand Down Expand Up @@ -622,7 +620,7 @@ void Group::Disband(bool hideDestroy, ObjectGuid initiator)

if (!isBGGroup())
{
CharacterDatabase.BeginTransaction();
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("DELETE FROM `groups` WHERE `group_id`='%u'", m_Id);
CharacterDatabase.PExecute("DELETE FROM `group_member` WHERE `group_id`='%u'", m_Id);
CharacterDatabase.CommitTransaction();
Expand Down Expand Up @@ -1584,8 +1582,11 @@ bool Group::_addMember(ObjectGuid guid, char const* name, bool isAssistant, uint
if (!isBGGroup() && !(player && player->IsSavingDisabled()))
{
// insert into group table
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("INSERT INTO `group_member` (`group_id`, `member_guid`, `assistant`, `subgroup`) VALUES('%u','%u','%u','%u')",
m_Id, member.guid.GetCounter(), ((member.assistant == 1) ? 1 : 0), member.group);
CharacterDatabase.CommitTransaction();

}

return true;
Expand Down Expand Up @@ -1620,7 +1621,11 @@ bool Group::_removeMember(ObjectGuid guid)
}

if (!isBGGroup())
{
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("DELETE FROM `group_member` WHERE `member_guid`='%u'", guid.GetCounter());
CharacterDatabase.CommitTransaction();
}

if (m_leaderGuid == guid) // leader was removed
{
Expand Down Expand Up @@ -1690,7 +1695,7 @@ void Group::_setLeader(ObjectGuid guid)
uint32 leader_lowguid = m_leaderGuid.GetCounter();

// TODO: set a time limit to have this function run rarely cause it can be slow
CharacterDatabase.BeginTransaction();
CharacterDatabase.BeginTransaction(m_Id);

// update the group's bound instances when changing leaders

Expand Down Expand Up @@ -1791,8 +1796,10 @@ bool Group::_swapMembersGroup(ObjectGuid guid, ObjectGuid swapGuid)
// Don't need to change group counters since we are swapping
if (!isBGGroup())
{
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("UPDATE `group_member` SET `subgroup`='%u' WHERE `member_guid`='%u'", slot->group, guid.GetCounter());
CharacterDatabase.PExecute("UPDATE `group_member` SET `subgroup`='%u' WHERE `member_guid`='%u'", swapSlot->group, swapGuid.GetCounter());
CharacterDatabase.CommitTransaction();
}

return true;
Expand All @@ -1809,7 +1816,11 @@ bool Group::_setMembersGroup(ObjectGuid guid, uint8 group)
SubGroupCounterIncrease(group);

if (!isBGGroup())
{
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("UPDATE `group_member` SET `subgroup`='%u' WHERE `member_guid`='%u'", group, guid.GetCounter());
CharacterDatabase.CommitTransaction();
}

return true;
}
Expand All @@ -1822,7 +1833,12 @@ bool Group::_setAssistantFlag(ObjectGuid guid, bool const& state)

slot->assistant = state;
if (!isBGGroup())
{
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("UPDATE `group_member` SET `assistant`='%u' WHERE `member_guid`='%u'", (state) ? 1 : 0, guid.GetCounter());
CharacterDatabase.CommitTransaction();
}

return true;
}

Expand All @@ -1844,7 +1860,11 @@ bool Group::_setMainTank(ObjectGuid guid)
m_mainTankGuid = guid;

if (!isBGGroup())
{
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("UPDATE `groups` SET `main_tank_guid`='%u' WHERE `group_id`='%u'", m_mainTankGuid.GetCounter(), m_Id);
CharacterDatabase.CommitTransaction();
}

return true;
}
Expand All @@ -1867,8 +1887,11 @@ bool Group::_setMainAssistant(ObjectGuid guid)
m_mainAssistantGuid = guid;

if (!isBGGroup())
CharacterDatabase.PExecute("UPDATE `groups` SET `main_assistant_guid`='%u' WHERE `group_id`='%u'",
m_mainAssistantGuid.GetCounter(), m_Id);
{
CharacterDatabase.BeginTransaction(m_Id);
CharacterDatabase.PExecute("UPDATE `groups` SET `main_assistant_guid`='%u' WHERE `group_id`='%u'", m_mainAssistantGuid.GetCounter(), m_Id);
CharacterDatabase.CommitTransaction();
}

return true;
}
Expand Down

0 comments on commit 2aae996

Please sign in to comment.