mirror of
https://github.com/EQEmu/Server.git
synced 2026-06-10 02:31:03 +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:
@@ -71,90 +71,6 @@ void ExpeditionDatabase::PurgeExpiredCharacterLockouts()
|
||||
database.QueryDatabase(query);
|
||||
}
|
||||
|
||||
std::vector<Expedition> ExpeditionDatabase::LoadExpeditions(uint32_t select_expedition_id)
|
||||
{
|
||||
std::vector<Expedition> expeditions;
|
||||
|
||||
std::string query = SQL(
|
||||
SELECT
|
||||
expeditions.id,
|
||||
expeditions.dynamic_zone_id,
|
||||
instance_list.id,
|
||||
instance_list.zone,
|
||||
instance_list.version,
|
||||
instance_list.start_time,
|
||||
instance_list.duration,
|
||||
expeditions.leader_id,
|
||||
expedition_members.character_id
|
||||
FROM expeditions
|
||||
INNER JOIN dynamic_zones ON expeditions.dynamic_zone_id = dynamic_zones.id
|
||||
INNER JOIN instance_list ON dynamic_zones.instance_id = instance_list.id
|
||||
INNER JOIN expedition_members ON expedition_members.expedition_id = expeditions.id
|
||||
AND expedition_members.is_current_member = TRUE
|
||||
);
|
||||
|
||||
if (select_expedition_id != 0)
|
||||
{
|
||||
query.append(fmt::format(" WHERE expeditions.id = {};", select_expedition_id));
|
||||
}
|
||||
else
|
||||
{
|
||||
query.append(" ORDER BY expeditions.id;");
|
||||
}
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (results.Success())
|
||||
{
|
||||
uint32_t last_expedition_id = 0;
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row)
|
||||
{
|
||||
uint32_t expedition_id = strtoul(row[0], nullptr, 10);
|
||||
|
||||
if (last_expedition_id != expedition_id)
|
||||
{
|
||||
DynamicZone dynamic_zone{
|
||||
static_cast<uint32_t>(strtoul(row[1], nullptr, 10)), // dz_id
|
||||
static_cast<uint32_t>(strtoul(row[3], nullptr, 10)), // dz_zone_id
|
||||
static_cast<uint32_t>(strtoul(row[2], nullptr, 10)), // dz_instance_id
|
||||
static_cast<uint32_t>(strtoul(row[4], nullptr, 10)), // dz_zone_version
|
||||
static_cast<uint32_t>(strtoul(row[5], nullptr, 10)), // start_time
|
||||
static_cast<uint32_t>(strtoul(row[6], nullptr, 10)), // duration
|
||||
DynamicZoneType::Expedition
|
||||
};
|
||||
|
||||
expeditions.emplace_back(
|
||||
expedition_id,
|
||||
dynamic_zone,
|
||||
static_cast<uint32_t>(strtoul(row[7], nullptr, 10)) // leader_id
|
||||
);
|
||||
}
|
||||
|
||||
last_expedition_id = expedition_id;
|
||||
|
||||
uint32_t member_id = static_cast<uint32_t>(strtoul(row[8], nullptr, 10));
|
||||
expeditions.back().AddMember(member_id);
|
||||
}
|
||||
}
|
||||
|
||||
return expeditions;
|
||||
}
|
||||
|
||||
Expedition ExpeditionDatabase::LoadExpedition(uint32_t expedition_id)
|
||||
{
|
||||
LogExpeditions("Loading expedition [{}] for world cache", expedition_id);
|
||||
|
||||
Expedition expedition;
|
||||
|
||||
auto expeditions = LoadExpeditions(expedition_id);
|
||||
if (!expeditions.empty())
|
||||
{
|
||||
expedition = expeditions.front();
|
||||
}
|
||||
|
||||
return expedition;
|
||||
}
|
||||
|
||||
void ExpeditionDatabase::DeleteExpeditions(const std::vector<uint32_t>& expedition_ids)
|
||||
{
|
||||
LogExpeditionsDetail("Deleting [{}] expedition(s)", expedition_ids.size());
|
||||
|
||||
Reference in New Issue
Block a user