delete unnecessary file caches

This commit is contained in:
Martin Michelsen
2026-05-25 07:58:39 -07:00
parent b8efd730f9
commit b59dde53b2
5 changed files with 12 additions and 56 deletions
-6
View File
@@ -2587,7 +2587,6 @@ Action a_describe_item(
Action a_name_all_items(
"name-all-items", nullptr, +[](phosg::Arguments& args) {
auto s = make_shared<ServerState>(get_config_filename(args));
s->clear_file_caches();
s->load_config_early();
s->load_patch_indexes();
s->load_text_index();
@@ -2674,7 +2673,6 @@ Action a_print_level_stats(
+[](phosg::Arguments& args) {
auto s = make_shared<ServerState>(get_config_filename(args));
s->load_config_early();
s->clear_file_caches();
s->load_patch_indexes();
s->load_level_tables();
@@ -2835,7 +2833,6 @@ Action a_generate_ep3_cards_html(
bool no_disassembly = args.get<bool>("no-disassembly");
auto s = make_shared<ServerState>(get_config_filename(args));
s->clear_file_caches();
s->load_patch_indexes();
s->load_text_index();
s->load_ep3_cards();
@@ -3133,7 +3130,6 @@ Action a_check_supermaps(
auto s = make_shared<ServerState>(get_config_filename(args));
s->load_config_early();
s->clear_file_caches();
s->load_patch_indexes();
s->load_set_data_tables();
s->load_maps();
@@ -3534,7 +3530,6 @@ Action a_print_free_supermap(
auto s = make_shared<ServerState>(get_config_filename(args));
s->load_config_early();
s->clear_file_caches();
s->load_patch_indexes();
s->load_set_data_tables();
s->load_maps();
@@ -3560,7 +3555,6 @@ Action a_check_quests(
auto s = make_shared<ServerState>(get_config_filename(args));
s->is_debug = true;
s->load_config_early();
s->clear_file_caches();
s->load_patch_indexes();
s->load_set_data_tables();
s->load_maps();
+2 -2
View File
@@ -3320,8 +3320,8 @@ static asio::awaitable<void> on_D7_GC(shared_ptr<Client> c, Channel::Message& ms
} else {
try {
auto s = c->require_server_state();
auto f = s->gba_files_cache->get_or_load("system/gba/" + filename).file;
send_open_quest_file(c, "", filename, "", 0, QuestFileType::GBA_DEMO, f->data);
auto data = std::make_shared<std::string>(phosg::load_file("system/gba/" + filename));
send_open_quest_file(c, "", filename, "", 0, QuestFileType::GBA_DEMO, data);
} catch (const out_of_range&) {
send_command(c, 0xD7, 0x00);
} catch (const phosg::cannot_open_file&) {
+9 -38
View File
@@ -78,9 +78,7 @@ ServerState::ServerState(const string& config_filename, bool is_replay)
io_context(make_shared<asio::io_context>(1)),
config_filename(config_filename),
is_replay(is_replay),
thread_pool(make_unique<asio::thread_pool>()),
bb_system_cache(new FileContentsCache(3600000000ULL)),
gba_files_cache(new FileContentsCache(3600000000ULL)) {}
thread_pool(make_unique<asio::thread_pool>()) {}
void ServerState::add_client_to_available_lobby(shared_ptr<Client> c, bool allow_games) {
shared_ptr<Lobby> added_to_lobby;
@@ -611,12 +609,11 @@ void ServerState::set_port_configuration(const vector<PortConfiguration>& port_c
}
}
shared_ptr<const string> ServerState::load_bb_file(
const string& patch_index_filename, const string& gsl_filename, const string& bb_directory_filename) const {
shared_ptr<const string> ServerState::load_bb_file(const string& filename) const {
if (this->bb_patch_file_index) {
// First, look in the patch tree's data directory
string patch_index_path = "./data/" + patch_index_filename;
string patch_index_path = "./data/" + filename;
try {
return this->bb_patch_file_index->get(patch_index_path)->load_data();
} catch (const out_of_range&) {
@@ -625,17 +622,16 @@ shared_ptr<const string> ServerState::load_bb_file(
if (this->bb_data_gsl) {
// Second, look in the patch tree's data.gsl file
const string& effective_gsl_filename = gsl_filename.empty() ? patch_index_filename : gsl_filename;
try {
// TODO: It's kinda not great that we copy the data here; find a way to avoid doing this (also in the below case)
return std::make_shared<string>(this->bb_data_gsl->get_copy(effective_gsl_filename));
return std::make_shared<string>(this->bb_data_gsl->get_copy(filename));
} catch (const out_of_range&) {
}
// Third, look in data.gsl without the filename extension
size_t dot_offset = effective_gsl_filename.rfind('.');
size_t dot_offset = filename.rfind('.');
if (dot_offset != string::npos) {
string no_ext_gsl_filename = effective_gsl_filename.substr(0, dot_offset);
string no_ext_gsl_filename = filename.substr(0, dot_offset);
try {
return std::make_shared<string>(this->bb_data_gsl->get_copy(no_ext_gsl_filename));
} catch (const out_of_range&) {
@@ -644,13 +640,7 @@ shared_ptr<const string> ServerState::load_bb_file(
}
// Finally, look in system/blueburst
const string& effective_bb_directory_filename = bb_directory_filename.empty() ? patch_index_filename : bb_directory_filename;
try {
auto ret = this->bb_system_cache->get_or_load("system/blueburst/" + effective_bb_directory_filename);
return ret.file->data;
} catch (const exception& e) {
throw phosg::cannot_open_file(patch_index_filename);
}
return std::make_shared<std::string>(phosg::load_file("system/blueburst/" + filename));
}
shared_ptr<const string> ServerState::load_map_file(Version version, const string& filename) const {
@@ -1853,13 +1843,6 @@ vector<shared_ptr<const SuperMap>> ServerState::supermaps_for_variations(
return ret;
}
void ServerState::clear_file_caches() {
config_log.info_f("Clearing BB system cache");
this->bb_system_cache.reset(new FileContentsCache(3600000000ULL));
config_log.info_f("Clearing GBA file cache");
this->gba_files_cache.reset(new FileContentsCache(300 * 1000 * 1000));
}
void ServerState::load_set_data_tables() {
config_log.info_f("Loading set data tables");
@@ -1901,19 +1884,8 @@ void ServerState::load_set_data_tables() {
void ServerState::load_battle_params() {
config_log.info_f("Loading JSON battle parameters");
try {
this->battle_params = std::make_shared<JSONBattleParamsIndex>(phosg::JSON::parse(phosg::load_file(
"system/tables/battle-params.json")));
} catch (const std::exception& e) {
config_log.info_f("Cannot load JSON battle parameters ({}); loading binary battle parameters", e.what());
this->battle_params = std::make_shared<BinaryBattleParamsIndex>(
this->load_bb_file("BattleParamEntry_on.dat"),
this->load_bb_file("BattleParamEntry_lab_on.dat"),
this->load_bb_file("BattleParamEntry_ep4_on.dat"),
this->load_bb_file("BattleParamEntry.dat"),
this->load_bb_file("BattleParamEntry_lab.dat"),
this->load_bb_file("BattleParamEntry_ep4.dat"));
}
this->battle_params = std::make_shared<JSONBattleParamsIndex>(phosg::JSON::parse(phosg::load_file(
"system/tables/battle-params.json")));
}
void ServerState::load_level_tables() {
@@ -2362,7 +2334,6 @@ void ServerState::load_all(bool enable_thread_pool) {
this->load_bb_private_keys();
this->load_bb_system_defaults();
this->load_accounts();
this->clear_file_caches();
this->load_patch_indexes();
this->load_ep3_cards();
this->load_ep3_maps();
+1 -7
View File
@@ -195,8 +195,6 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::unordered_map<uint32_t, std::shared_ptr<const SuperMap>> supermap_for_free_play_key;
std::shared_ptr<const RoomLayoutIndex> room_layout_index;
std::shared_ptr<const BBStreamFile> bb_stream_file;
std::shared_ptr<FileContentsCache> bb_system_cache;
std::shared_ptr<FileContentsCache> gba_files_cache;
std::shared_ptr<const DOLFileIndex> dol_file_index;
std::shared_ptr<const Episode3::CardIndex> ep3_card_index;
std::shared_ptr<const Episode3::CardIndex> ep3_card_index_trial;
@@ -404,10 +402,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
void set_port_configuration(const std::vector<PortConfiguration>& port_configs);
std::shared_ptr<const std::string> load_bb_file(
const std::string& patch_index_filename,
const std::string& gsl_filename = "",
const std::string& bb_directory_filename = "") const;
std::shared_ptr<const std::string> load_bb_file(const std::string& patch_index_filename) const;
std::shared_ptr<const std::string> load_map_file(Version version, const std::string& filename) const;
std::shared_ptr<const std::string> load_map_file_uncached(Version version, const std::string& filename) const;
@@ -438,7 +433,6 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
void load_teams();
void load_patch_indexes();
void load_maps();
void clear_file_caches();
void load_battle_params();
void load_level_tables();
void load_text_index();
-3
View File
@@ -158,7 +158,6 @@ ShellCommand c_reload(
accounts - reindex user accounts\n\
battle-params - reload the BB enemy stats files\n\
bb-keys - reload BB private keys\n\
caches - clear all cached files\n\
config - reload most fields from config.json\n\
dol-files - reindex all DOL files\n\
drop-tables - reload drop tables\n\
@@ -193,8 +192,6 @@ ShellCommand c_reload(
args.s->load_accounts();
} else if (type == "maps") {
args.s->load_maps();
} else if (type == "caches") {
args.s->clear_file_caches();
} else if (type == "patch-files") {
args.s->load_patch_indexes();
} else if (type == "ep3-cards") {