diff --git a/src/core/game_database.cpp b/src/core/game_database.cpp index e08d08539..90b2865ba 100644 --- a/src/core/game_database.cpp +++ b/src/core/game_database.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,8 @@ enum : u32 static const Entry* GetEntryForId(std::string_view code); +static void EnsureLoaded(); +static void Load(); static bool LoadFromCache(); static bool SaveToCache(); @@ -174,6 +177,8 @@ struct ALIGN_TO_CACHE_LINE State PreferUnorderedStringMap code_lookup; TrackHashesMap track_hashes_map; + + std::once_flag load_once_flag; }; } // namespace @@ -186,9 +191,12 @@ void GameDatabase::EnsureLoaded() if (s_state.loaded) return; - Timer timer; + std::call_once(s_state.load_once_flag, &GameDatabase::Load); +} - s_state.loaded = true; +void GameDatabase::Load() +{ + Timer timer; if (!LoadFromCache()) { @@ -210,14 +218,9 @@ void GameDatabase::EnsureLoaded() } } - INFO_LOG("Database load of {} entries took {:.0f}ms.", s_state.entries.size(), timer.GetTimeMilliseconds()); -} + s_state.loaded = true; -void GameDatabase::Unload() -{ - s_state.entries = {}; - s_state.code_lookup = {}; - s_state.loaded = false; + INFO_LOG("Database load of {} entries took {:.0f}ms.", s_state.entries.size(), timer.GetTimeMilliseconds()); } const GameDatabase::Entry* GameDatabase::GetEntryForId(std::string_view code) diff --git a/src/core/game_database.h b/src/core/game_database.h index d0dc85074..199c360da 100644 --- a/src/core/game_database.h +++ b/src/core/game_database.h @@ -196,9 +196,6 @@ struct DiscSetEntry std::string_view GetFirstSerial() const; }; -void EnsureLoaded(); -void Unload(); - const Entry* GetEntryForDisc(CDImage* image); const Entry* GetEntryForGameDetails(const std::string& id, u64 hash); const Entry* GetEntryForSerial(std::string_view serial);