aboutsummaryrefslogtreecommitdiff
path: root/src/db/ProxyDatabasePlugin.cxx
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/ProxyDatabasePlugin.cxx
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/ProxyDatabasePlugin.cxx')
-rw-r--r--src/db/ProxyDatabasePlugin.cxx52
1 files changed, 52 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,