Commit 98108050 authored by Max Kellermann's avatar Max Kellermann

Stats: pass Database reference around

Call GetDatabase() only once.
parent 636d28b7
...@@ -66,7 +66,7 @@ stats_invalidate() ...@@ -66,7 +66,7 @@ stats_invalidate()
} }
static bool static bool
stats_update() stats_update(const Database &db)
{ {
switch (stats_validity) { switch (stats_validity) {
case StatsValidity::INVALID: case StatsValidity::INVALID:
...@@ -82,7 +82,7 @@ stats_update() ...@@ -82,7 +82,7 @@ stats_update()
Error error; Error error;
const DatabaseSelection selection("", true); const DatabaseSelection selection("", true);
if (GetDatabase()->GetStats(selection, stats, error)) { if (db.GetStats(selection, stats, error)) {
stats_validity = StatsValidity::VALID; stats_validity = StatsValidity::VALID;
return true; return true;
} else { } else {
...@@ -94,11 +94,9 @@ stats_update() ...@@ -94,11 +94,9 @@ stats_update()
} }
static void static void
db_stats_print(Client &client) db_stats_print(Client &client, const Database &db)
{ {
assert(GetDatabase() != nullptr); if (!stats_update(db))
if (!stats_update())
return; return;
client_printf(client, client_printf(client,
...@@ -111,7 +109,7 @@ db_stats_print(Client &client) ...@@ -111,7 +109,7 @@ db_stats_print(Client &client)
stats.song_count, stats.song_count,
stats.total_duration); stats.total_duration);
const time_t update_stamp = GetDatabase()->GetUpdateStamp(); const time_t update_stamp = db.GetUpdateStamp();
if (update_stamp > 0) if (update_stamp > 0)
client_printf(client, client_printf(client,
"db_update: %lu\n", "db_update: %lu\n",
...@@ -134,7 +132,8 @@ stats_print(Client &client) ...@@ -134,7 +132,8 @@ stats_print(Client &client)
(unsigned long)(client.player_control.GetTotalPlayTime() + 0.5)); (unsigned long)(client.player_control.GetTotalPlayTime() + 0.5));
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (GetDatabase() != nullptr) const Database *db = GetDatabase();
db_stats_print(client); if (db != nullptr)
db_stats_print(client, *db);
#endif #endif
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment