From 3c0dea811d498db3091dad868740c4653c22717e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 22:20:28 +0200 Subject: DatabasePlugin: add method GetStats() Optimize the ProxyDatabase by invoking "stats" on the peer, instead of visiting all songs. --- src/db/ProxyDatabasePlugin.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/db/ProxyDatabasePlugin.cxx') diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx index f06728f80..3525e6f09 100644 --- a/src/db/ProxyDatabasePlugin.cxx +++ b/src/db/ProxyDatabasePlugin.cxx @@ -67,6 +67,10 @@ public: VisitString visit_string, GError **error_r) const override; + virtual bool GetStats(const DatabaseSelection &selection, + DatabaseStats &stats, + GError **error_r) const override; + protected: bool Configure(const struct config_param *param, GError **error_r); }; @@ -420,6 +424,27 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection, result; } +bool +ProxyDatabase::GetStats(const DatabaseSelection &selection, + DatabaseStats &stats, GError **error_r) const +{ + // TODO: match + (void)selection; + + struct mpd_stats *stats2 = + mpd_run_stats(connection); + if (stats2 == nullptr) + return CheckError(connection, error_r); + + stats.song_count = mpd_stats_get_number_of_songs(stats2); + stats.total_duration = mpd_stats_get_db_play_time(stats2); + stats.artist_count = mpd_stats_get_number_of_artists(stats2); + stats.album_count = mpd_stats_get_number_of_albums(stats2); + mpd_stats_free(stats2); + + return true; +} + const DatabasePlugin proxy_db_plugin = { "proxy", ProxyDatabase::Create, -- cgit v1.2.3