mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-09 22:20:24 +00:00
[Expeditions] Refactor expedition caching (#1315)
Add common expedition base class Use repository for zone and world expedition caching World now stores members and leader as Member objects instead of ids This improves readability of the caching methods and lets world cache expedition dzs and members like zone. World also now caches expeditions as unique_ptr which will be necessary for future dz callback lambdas that capture 'this' so addresses don't change on cache vector resizes.
This commit is contained in:
@@ -51,52 +51,6 @@ uint32_t ExpeditionDatabase::InsertExpedition(
|
||||
return results.LastInsertedID();
|
||||
}
|
||||
|
||||
std::string ExpeditionDatabase::LoadExpeditionsSelectQuery()
|
||||
{
|
||||
return std::string(SQL(
|
||||
SELECT
|
||||
expeditions.id,
|
||||
expeditions.uuid,
|
||||
expeditions.dynamic_zone_id,
|
||||
expeditions.expedition_name,
|
||||
expeditions.leader_id,
|
||||
expeditions.min_players,
|
||||
expeditions.max_players,
|
||||
expeditions.add_replay_on_join,
|
||||
expeditions.is_locked,
|
||||
character_data.name leader_name,
|
||||
expedition_members.character_id,
|
||||
member_data.name
|
||||
FROM expeditions
|
||||
INNER JOIN character_data ON expeditions.leader_id = character_data.id
|
||||
INNER JOIN expedition_members ON expeditions.id = expedition_members.expedition_id
|
||||
AND expedition_members.is_current_member = TRUE
|
||||
INNER JOIN character_data member_data ON expedition_members.character_id = member_data.id
|
||||
));
|
||||
}
|
||||
|
||||
MySQLRequestResult ExpeditionDatabase::LoadExpedition(uint32_t expedition_id)
|
||||
{
|
||||
LogExpeditionsDetail("Loading expedition [{}]", expedition_id);
|
||||
|
||||
std::string query = fmt::format(SQL(
|
||||
{} WHERE expeditions.id = {};
|
||||
), LoadExpeditionsSelectQuery(), expedition_id);
|
||||
|
||||
return database.QueryDatabase(query);
|
||||
}
|
||||
|
||||
MySQLRequestResult ExpeditionDatabase::LoadAllExpeditions()
|
||||
{
|
||||
LogExpeditionsDetail("Loading all expeditions from database");
|
||||
|
||||
std::string query = fmt::format(SQL(
|
||||
{} ORDER BY expeditions.id;
|
||||
), LoadExpeditionsSelectQuery());
|
||||
|
||||
return database.QueryDatabase(query);
|
||||
}
|
||||
|
||||
std::vector<ExpeditionLockoutTimer> ExpeditionDatabase::LoadCharacterLockouts(uint32_t character_id)
|
||||
{
|
||||
LogExpeditionsDetail("Loading character [{}] lockouts", character_id);
|
||||
@@ -170,54 +124,6 @@ std::vector<ExpeditionLockoutTimer> ExpeditionDatabase::LoadCharacterLockouts(
|
||||
return lockouts;
|
||||
}
|
||||
|
||||
std::unordered_map<uint32_t, std::unordered_map<std::string, ExpeditionLockoutTimer>>
|
||||
ExpeditionDatabase::LoadMultipleExpeditionLockouts(
|
||||
const std::vector<uint32_t>& expedition_ids)
|
||||
{
|
||||
LogExpeditionsDetail("Loading internal lockouts for [{}] expeditions", expedition_ids.size());
|
||||
|
||||
std::string in_expedition_ids_query = fmt::format("{}", fmt::join(expedition_ids, ","));
|
||||
|
||||
// these are loaded into the same container type expeditions use to store lockouts
|
||||
std::unordered_map<uint32_t, std::unordered_map<std::string, ExpeditionLockoutTimer>> lockouts;
|
||||
|
||||
if (!in_expedition_ids_query.empty())
|
||||
{
|
||||
std::string query = fmt::format(SQL(
|
||||
SELECT
|
||||
expedition_lockouts.expedition_id,
|
||||
expedition_lockouts.from_expedition_uuid,
|
||||
expeditions.expedition_name,
|
||||
expedition_lockouts.event_name,
|
||||
UNIX_TIMESTAMP(expedition_lockouts.expire_time),
|
||||
expedition_lockouts.duration
|
||||
FROM expedition_lockouts
|
||||
INNER JOIN expeditions ON expedition_lockouts.expedition_id = expeditions.id
|
||||
WHERE expedition_id IN ({})
|
||||
ORDER BY expedition_id;
|
||||
), in_expedition_ids_query);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
|
||||
if (results.Success())
|
||||
{
|
||||
for (auto row = results.begin(); row != results.end(); ++row)
|
||||
{
|
||||
auto expedition_id = strtoul(row[0], nullptr, 10);
|
||||
lockouts[expedition_id].emplace(row[3], ExpeditionLockoutTimer{
|
||||
row[1], // expedition_uuid
|
||||
row[2], // expedition_name
|
||||
row[3], // event_name
|
||||
strtoull(row[4], nullptr, 10), // expire_time
|
||||
static_cast<uint32_t>(strtoul(row[5], nullptr, 10)) // original duration
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lockouts;
|
||||
}
|
||||
|
||||
void ExpeditionDatabase::DeleteAllCharacterLockouts(uint32_t character_id)
|
||||
{
|
||||
LogExpeditionsDetail("Deleting all character [{}] lockouts", character_id);
|
||||
|
||||
Reference in New Issue
Block a user