aboutsummaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-15 21:32:34 +0200
committerMax Kellermann <max@duempel.org>2012-08-15 23:02:27 +0200
commita6ac0f89656b9ef374703d24bbb27316a705eadc (patch)
tree3706b1b8474ae06890595a8e20c8be011f6a162b /src/db
parent4e1eb03287c1af889372ed4c63220a88d2032f78 (diff)
DatabasePlugin: add method VisitUniqueTags()
Optimize the ProxyDatabase by invoking "list" on the peer, instead of visiting all songs.
Diffstat (limited to 'src/db')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx52
-rw-r--r--src/db/SimpleDatabasePlugin.cxx11
-rw-r--r--src/db/SimpleDatabasePlugin.hxx5
3 files changed, 68 insertions, 0 deletions
diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx
index 68ba5a54..f06728f8 100644
--- a/src/db/ProxyDatabasePlugin.cxx
+++ b/src/db/ProxyDatabasePlugin.cxx
@@ -62,6 +62,11 @@ public:
VisitPlaylist visit_playlist,
GError **error_r) const override;
+ virtual bool VisitUniqueTags(const DatabaseSelection &selection,
+ enum tag_type tag_type,
+ VisitString visit_string,
+ GError **error_r) const override;
+
protected:
bool Configure(const struct config_param *param, GError **error_r);
};
@@ -97,6 +102,17 @@ static constexpr struct {
{ TAG_NUM_OF_ITEM_TYPES, MPD_TAG_COUNT }
};
+G_GNUC_CONST
+static enum mpd_tag_type
+Convert(enum tag_type tag_type)
+{
+ for (auto i = tag_table; i->d != TAG_NUM_OF_ITEM_TYPES; ++i)
+ if (i->d == tag_type)
+ return i->s;
+
+ return MPD_TAG_COUNT;
+}
+
static bool
CheckError(const struct mpd_connection *connection, GError **error_r)
{
@@ -368,6 +384,42 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
return success;
}
+bool
+ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
+ enum tag_type tag_type,
+ VisitString visit_string,
+ GError **error_r) const
+{
+ enum mpd_tag_type tag_type2 = Convert(tag_type);
+ if (tag_type2 == MPD_TAG_COUNT) {
+ g_set_error_literal(error_r, libmpdclient_quark(), 0,
+ "Unsupported tag");
+ return false;
+ }
+
+ if (!mpd_search_db_tags(connection, tag_type2))
+ return CheckError(connection, error_r);
+
+ // TODO: match
+ (void)selection;
+
+ if (!mpd_search_commit(connection))
+ return CheckError(connection, error_r);
+
+ bool result = true;
+
+ struct mpd_pair *pair;
+ while (result &&
+ (pair = mpd_recv_pair_tag(connection, tag_type2)) != nullptr) {
+ result = visit_string(pair->value, error_r);
+ mpd_return_pair(connection, pair);
+ }
+
+ return mpd_response_finish(connection) &&
+ CheckError(connection, error_r) &&
+ result;
+}
+
const DatabasePlugin proxy_db_plugin = {
"proxy",
ProxyDatabase::Create,
diff --git a/src/db/SimpleDatabasePlugin.cxx b/src/db/SimpleDatabasePlugin.cxx
index a4077eb2..ed166de4 100644
--- a/src/db/SimpleDatabasePlugin.cxx
+++ b/src/db/SimpleDatabasePlugin.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "SimpleDatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
+#include "DatabaseHelpers.hxx"
extern "C" {
#include "db_error.h"
@@ -270,6 +271,16 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
}
bool
+SimpleDatabase::VisitUniqueTags(const DatabaseSelection &selection,
+ enum tag_type tag_type,
+ VisitString visit_string,
+ GError **error_r) const
+{
+ return ::VisitUniqueTags(*this, selection, tag_type, visit_string,
+ error_r);
+}
+
+bool
SimpleDatabase::Save(GError **error_r)
{
db_lock();
diff --git a/src/db/SimpleDatabasePlugin.hxx b/src/db/SimpleDatabasePlugin.hxx
index 1e990de1..0b7e838b 100644
--- a/src/db/SimpleDatabasePlugin.hxx
+++ b/src/db/SimpleDatabasePlugin.hxx
@@ -66,6 +66,11 @@ public:
VisitPlaylist visit_playlist,
GError **error_r) const override;
+ virtual bool VisitUniqueTags(const DatabaseSelection &selection,
+ enum tag_type tag_type,
+ VisitString visit_string,
+ GError **error_r) const override;
+
protected:
bool Configure(const struct config_param *param, GError **error_r);