aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-15 22:20:28 +0200
committerMax Kellermann <max@duempel.org>2012-08-15 23:05:08 +0200
commit3c0dea811d498db3091dad868740c4653c22717e (patch)
tree698de51e854a052d43cb3f872a5aee5b608fb71f /src/db
parenta6ac0f89656b9ef374703d24bbb27316a705eadc (diff)
downloadmpd-3c0dea811d498db3091dad868740c4653c22717e.tar.gz
mpd-3c0dea811d498db3091dad868740c4653c22717e.tar.xz
mpd-3c0dea811d498db3091dad868740c4653c22717e.zip
DatabasePlugin: add method GetStats()
Optimize the ProxyDatabase by invoking "stats" on the peer, instead of visiting all songs.
Diffstat (limited to 'src/db')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx25
-rw-r--r--src/db/SimpleDatabasePlugin.cxx7
-rw-r--r--src/db/SimpleDatabasePlugin.hxx5
3 files changed, 37 insertions, 0 deletions
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,
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index ed166de45..c1de70d3e 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -281,6 +281,13 @@ SimpleDatabase::VisitUniqueTags(const DatabaseSelection &selection,
}
bool
+SimpleDatabase::GetStats(const DatabaseSelection &selection,
+ DatabaseStats &stats, GError **error_r) const
+{
+ return ::GetStats(*this, selection, stats, error_r);
+}
+
+bool
SimpleDatabase::Save(GError **error_r)
{
db_lock();
diff --git a/src/db/SimpleDatabasePlugin.hxx b/src/db/SimpleDatabasePlugin.hxx
index 0b7e838b5..7e3f5d2db 100644
--- a/src/db/SimpleDatabasePlugin.hxx
+++ b/src/db/SimpleDatabasePlugin.hxx
@@ -58,6 +58,7 @@ public:
virtual bool Open(GError **error_r) override;
virtual void Close() override;
+
virtual struct song *GetSong(const char *uri_utf8,
GError **error_r) const override;
virtual bool Visit(const DatabaseSelection &selection,
@@ -71,6 +72,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);