Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/2] Remove unnecessary empty line in phonebook-tracker
@ 2010-10-26  8:29 Radoslaw Jablonski
  2010-10-26  8:29 ` [PATCH 2/2] Add separate queries for listing size in PBAP Radoslaw Jablonski
  0 siblings, 1 reply; 3+ messages in thread
From: Radoslaw Jablonski @ 2010-10-26  8:29 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Radoslaw Jablonski

---
 plugins/phonebook-tracker.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index a6e21f8..277290c 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -531,7 +531,6 @@
 		"}"							\
 	"} GROUP BY ?call ORDER BY DESC(nmo:receivedDate(?call))"
 
-
 #define CONTACTS_QUERY_FROM_URI						\
 	"SELECT ?v nco:fullname(<%s>) "					\
 	"nco:nameFamily(<%s>) nco:nameGiven(<%s>) "			\
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Add separate queries for listing size in PBAP
  2010-10-26  8:29 [PATCH 1/2] Remove unnecessary empty line in phonebook-tracker Radoslaw Jablonski
@ 2010-10-26  8:29 ` Radoslaw Jablonski
  2010-10-26 14:07   ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Radoslaw Jablonski @ 2010-10-26  8:29 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Radoslaw Jablonski

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] Add separate queries for listing size in PBAP
  2010-10-26  8:29 ` [PATCH 2/2] Add separate queries for listing size in PBAP Radoslaw Jablonski
@ 2010-10-26 14:07   ` Johan Hedberg
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2010-10-26 14:07 UTC (permalink / raw)
  To: Radoslaw Jablonski; +Cc: linux-bluetooth

Hi Radek,

On Tue, Oct 26, 2010, Radoslaw Jablonski wrote:
> 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(-)

Both patches have been pushed upstream. Thanks.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-10-26 14:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-26  8:29 [PATCH 1/2] Remove unnecessary empty line in phonebook-tracker Radoslaw Jablonski
2010-10-26  8:29 ` [PATCH 2/2] Add separate queries for listing size in PBAP Radoslaw Jablonski
2010-10-26 14:07   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox