Core/Calendar: Use single database transaction for adding multiple invites when creating new event
This commit is contained in:
@@ -127,6 +127,12 @@ void CalendarMgr::AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType s
|
||||
}
|
||||
|
||||
void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite)
|
||||
{
|
||||
SQLTransaction dummy;
|
||||
AddInvite(calendarEvent, invite, dummy);
|
||||
}
|
||||
|
||||
void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite, SQLTransaction& trans)
|
||||
{
|
||||
if (!calendarEvent->IsGuildAnnouncement())
|
||||
SendCalendarEventInvite(*invite);
|
||||
@@ -137,7 +143,7 @@ void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite
|
||||
if (!calendarEvent->IsGuildAnnouncement())
|
||||
{
|
||||
_invites[invite->GetEventId()].push_back(invite);
|
||||
UpdateInvite(invite);
|
||||
UpdateInvite(invite, trans);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +227,6 @@ void CalendarMgr::RemoveInvite(uint64 inviteId, uint64 eventId, uint64 /*remover
|
||||
|
||||
void CalendarMgr::UpdateEvent(CalendarEvent* calendarEvent)
|
||||
{
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_EVENT);
|
||||
stmt->setUInt64(0, calendarEvent->GetEventId());
|
||||
stmt->setUInt32(1, GUID_LOPART(calendarEvent->GetCreatorGUID()));
|
||||
@@ -232,13 +237,17 @@ void CalendarMgr::UpdateEvent(CalendarEvent* calendarEvent)
|
||||
stmt->setUInt32(6, uint32(calendarEvent->GetEventTime()));
|
||||
stmt->setUInt32(7, calendarEvent->GetFlags());
|
||||
stmt->setUInt32(8, calendarEvent->GetTimeZoneTime()); // correct?
|
||||
trans->Append(stmt);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
CharacterDatabase.Execute(stmt);
|
||||
}
|
||||
|
||||
void CalendarMgr::UpdateInvite(CalendarInvite* invite)
|
||||
{
|
||||
SQLTransaction trans = CharacterDatabase.BeginTransaction();
|
||||
SQLTransaction dummy;
|
||||
UpdateInvite(invite, dummy);
|
||||
}
|
||||
|
||||
void CalendarMgr::UpdateInvite(CalendarInvite* invite, SQLTransaction& trans)
|
||||
{
|
||||
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_INVITE);
|
||||
stmt->setUInt64(0, invite->GetInviteId());
|
||||
stmt->setUInt64(1, invite->GetEventId());
|
||||
@@ -248,8 +257,7 @@ void CalendarMgr::UpdateInvite(CalendarInvite* invite)
|
||||
stmt->setUInt32(5, uint32(invite->GetStatusTime()));
|
||||
stmt->setUInt8(6, invite->GetRank());
|
||||
stmt->setString(7, invite->GetText());
|
||||
trans->Append(stmt);
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
CharacterDatabase.ExecuteOrAppend(trans, stmt);
|
||||
}
|
||||
|
||||
void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid)
|
||||
|
||||
@@ -305,8 +305,10 @@ class CalendarMgr
|
||||
void UpdateEvent(CalendarEvent* calendarEvent);
|
||||
|
||||
void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite);
|
||||
void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite, SQLTransaction& trans);
|
||||
void RemoveInvite(uint64 inviteId, uint64 eventId, uint64 remover);
|
||||
void UpdateInvite(CalendarInvite* invite);
|
||||
void UpdateInvite(CalendarInvite* invite, SQLTransaction& trans);
|
||||
|
||||
void RemoveAllPlayerEventsAndInvites(uint64 guid);
|
||||
void RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId);
|
||||
|
||||
@@ -255,6 +255,10 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
|
||||
uint32 inviteCount;
|
||||
recvData >> inviteCount;
|
||||
|
||||
SQLTransaction trans;
|
||||
if (inviteCount > 1)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
for (uint32 i = 0; i < inviteCount; ++i)
|
||||
{
|
||||
uint64 invitee = 0;
|
||||
@@ -265,8 +269,11 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData)
|
||||
|
||||
// 946684800 is 01/01/2000 00:00:00 - default response time
|
||||
CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent.GetEventId(), invitee, guid, 946684800, CalendarInviteStatus(status), CalendarModerationRank(rank), "");
|
||||
sCalendarMgr->AddInvite(&calendarEvent, invite);
|
||||
sCalendarMgr->AddInvite(&calendarEvent, invite, trans);
|
||||
}
|
||||
|
||||
if (inviteCount > 1)
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
}
|
||||
|
||||
sCalendarMgr->AddEvent(new CalendarEvent(calendarEvent, calendarEvent.GetEventId()), CALENDAR_SENDTYPE_ADD);
|
||||
@@ -350,10 +357,15 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData)
|
||||
sCalendarMgr->AddEvent(newEvent, CALENDAR_SENDTYPE_COPY);
|
||||
|
||||
CalendarInviteStore invites = sCalendarMgr->GetEventInvites(eventId);
|
||||
SQLTransaction trans;
|
||||
if (invites.size() > 1)
|
||||
trans = CharacterDatabase.BeginTransaction();
|
||||
|
||||
for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
|
||||
sCalendarMgr->AddInvite(newEvent, new CalendarInvite(**itr, sCalendarMgr->GetFreeInviteId(), newEvent->GetEventId()));
|
||||
sCalendarMgr->AddInvite(newEvent, new CalendarInvite(**itr, sCalendarMgr->GetFreeInviteId(), newEvent->GetEventId()), trans);
|
||||
|
||||
if (invites.size() > 1)
|
||||
CharacterDatabase.CommitTransaction(trans);
|
||||
// should we change owner when somebody makes a copy of event owned by another person?
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user