[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:
hg
2021-04-07 02:20:35 -04:00
committed by GitHub
parent 0534a2c6be
commit dadc1b2843
27 changed files with 580 additions and 559 deletions
@@ -65,6 +65,68 @@ public:
// Custom extended repository methods here
struct MemberWithName {
uint32_t id;
uint32_t expedition_id;
uint32_t character_id;
int is_current_member;
std::string character_name;
};
static std::string SelectMembersWithNames()
{
return std::string(SQL(
SELECT
expedition_members.id,
expedition_members.expedition_id,
expedition_members.character_id,
expedition_members.is_current_member,
character_data.name
FROM expedition_members
INNER JOIN character_data ON expedition_members.character_id = character_data.id
));
}
static std::vector<MemberWithName> GetWithNames(Database& db,
const std::vector<uint32_t>& expedition_ids)
{
if (expedition_ids.empty())
{
return {};
}
std::vector<MemberWithName> all_entries;
auto results = db.QueryDatabase(fmt::format(SQL(
{}
WHERE expedition_members.expedition_id IN ({})
AND expedition_members.is_current_member = TRUE;
),
SelectMembersWithNames(),
fmt::join(expedition_ids, ",")
));
if (results.Success())
{
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row)
{
MemberWithName entry{};
int col = 0;
entry.id = strtoul(row[col++], nullptr, 10);
entry.expedition_id = strtoul(row[col++], nullptr, 10);
entry.character_id = strtoul(row[col++], nullptr, 10);
entry.is_current_member = strtoul(row[col++], nullptr, 10);
entry.character_name = row[col++];
all_entries.emplace_back(std::move(entry));
}
}
return all_entries;
}
};
#endif //EQEMU_EXPEDITION_MEMBERS_REPOSITORY_H