[PATCH 2/2] Add separate queries for listing size in PBAP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Previosly to get phonebook-size or call history size, full phonebook
query was used and a lot of unnecessary operations need to be done on
that returned data.  Now separate query is used to get size of each
listing so performance for "getPhonebookSize" operations improved a lot.
---
 plugins/phonebook-tracker.c |  105 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 103 insertions(+), 2 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 277290c..3367e49 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -45,6 +45,7 @@
 #define TRACKER_DEFAULT_CONTACT_ME "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#default-contact-me";
 #define CONTACTS_ID_COL 38
 #define PULL_QUERY_COL_AMOUNT 39
+#define COUNT_QUERY_COL_AMOUNT 1
 #define COL_HOME_NUMBER 0
 #define COL_HOME_EMAIL 7
 #define COL_WORK_NUMBER 8
@@ -579,6 +580,59 @@
 		"<%s> nco:hasPhoneNumber ?t . "				\
 	"} "
 
+#define CONTACTS_COUNT_QUERY						\
+	"SELECT COUNT(?c) "						\
+	"WHERE {"							\
+		"?c a nco:PersonContact ."				\
+		"FILTER (regex(str(?c), \"contact:\") || "		\
+		"regex(str(?c), \"nco#default-contact-me\"))"		\
+	"}"
+
+#define MISSED_CALLS_COUNT_QUERY					\
+	"SELECT COUNT(?call) WHERE {"					\
+		"?c a nco:Contact ;"					\
+		"nco:hasPhoneNumber ?h ."				\
+		"?call a nmo:Call ;"					\
+		"nmo:isSent false ;"					\
+		"nmo:from ?c ;"						\
+		"nmo:isAnswered false ."				\
+	"}"
+
+#define INCOMING_CALLS_COUNT_QUERY					\
+	"SELECT COUNT(?call) WHERE {"					\
+		"?c a nco:Contact ;"					\
+		"nco:hasPhoneNumber ?h ."				\
+		"?call a nmo:Call ;"					\
+		"nmo:isSent false ;"					\
+		"nmo:from ?c ;"						\
+		"nmo:isAnswered true ."					\
+	"}"
+
+#define OUTGOING_CALLS_COUNT_QUERY					\
+	"SELECT COUNT(?call) WHERE {"					\
+		"?c a nco:Contact ;"					\
+		"nco:hasPhoneNumber ?h ."				\
+		"?call a nmo:Call ;"					\
+		"nmo:isSent true ;"					\
+		"nmo:to ?c ."						\
+	"}"
+
+#define COMBINED_CALLS_COUNT_QUERY					\
+	"SELECT COUNT(?call) WHERE {"					\
+	"{"								\
+		"?c a nco:Contact ;"					\
+		"nco:hasPhoneNumber ?h ."				\
+		"?call a nmo:Call ;"					\
+		"nmo:isSent true ;"					\
+		"nmo:to ?c ."						\
+	"}UNION {"							\
+		"?c a nco:Contact ;"					\
+		"nco:hasPhoneNumber ?h ."				\
+		"?call a nmo:Call ;"					\
+		"nmo:from ?c ."						\
+	"}"								\
+	"}"
+
 typedef void (*reply_list_foreach_t) (char **reply, int num_fields,
 		void *user_data);
 
@@ -633,6 +687,22 @@ static const char *name2query(const char *name)
 	return NULL;
 }
 
+static const char *name2count_query(const char *name)
+{
+	if (g_str_equal(name, "telecom/pb.vcf"))
+		return CONTACTS_COUNT_QUERY;
+	else if (g_str_equal(name, "telecom/ich.vcf"))
+		return INCOMING_CALLS_COUNT_QUERY;
+	else if (g_str_equal(name, "telecom/och.vcf"))
+		return OUTGOING_CALLS_COUNT_QUERY;
+	else if (g_str_equal(name, "telecom/mch.vcf"))
+		return MISSED_CALLS_COUNT_QUERY;
+	else if (g_str_equal(name, "telecom/cch.vcf"))
+		return COMBINED_CALLS_COUNT_QUERY;
+
+	return NULL;
+}
+
 static gboolean folder_is_valid(const char *folder)
 {
 	if (folder == NULL)
@@ -1022,6 +1092,26 @@ static GString *gen_vcards(GSList *contacts,
 	return vcards;
 }
 
+static void pull_contacts_size (char **reply, int num_fields, void *user_data)
+{
+	struct phonebook_data *data = user_data;
+
+	if (num_fields < 0) {
+		data->cb(NULL, 0, num_fields, 0, data->user_data);
+		goto fail;
+	}
+
+	if (reply != NULL) {
+		data->index = atoi(reply[0]);
+		return;
+	}
+
+	data->cb(NULL, 0, data->index, 0, data->user_data);
+
+fail:
+	g_free(data);
+}
+
 static void pull_contacts(char **reply, int num_fields, void *user_data)
 {
 	struct phonebook_data *data = user_data;
@@ -1284,10 +1374,21 @@ int phonebook_pull(const char *name, const struct apparam_field *params,
 {
 	struct phonebook_data *data;
 	const char *query;
+	reply_list_foreach_t pull_cb;
+	int col_amount;
 
 	DBG("name %s", name);
 
-	query = name2query(name);
+	if (params->maxlistcount == 0) {
+		query = name2count_query(name);
+		col_amount = COUNT_QUERY_COL_AMOUNT;
+		pull_cb = pull_contacts_size;
+	} else {
+		query = name2query(name);
+		col_amount = PULL_QUERY_COL_AMOUNT;
+		pull_cb = pull_contacts;
+	}
+
 	if (query == NULL)
 		return -ENOENT;
 
@@ -1296,7 +1397,7 @@ int phonebook_pull(const char *name, const struct apparam_field *params,
 	data->user_data = user_data;
 	data->cb = cb;
 
-	return query_tracker(query, PULL_QUERY_COL_AMOUNT, pull_contacts, data);
+	return query_tracker(query, col_amount, pull_cb, data);
 }
 
 int phonebook_get_entry(const char *folder, const char *id,
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux