[PATCH 1/2] Optimize call history queries

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

 



From 59bad107ec51e6824b0c4450f4c67ab1e4505cff Mon Sep 17 00:00:00 2001
From: Rafal Michalski <michalski.raf@xxxxxxxxx>
Date: Wed, 27 Oct 2010 09:19:21 +0200
Subject: [PATCH 1/2] Optimize call history queries

This patch optimizes call history queries - now there is no redundant
results of invoking them.
---
 plugins/phonebook-tracker.c |   74 ++++++++++++++++++++----------------------
 1 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/plugins/phonebook-tracker.c b/plugins/phonebook-tracker.c
index 3367e49..e037677 100644
--- a/plugins/phonebook-tracker.c
+++ b/plugins/phonebook-tracker.c
@@ -128,6 +128,13 @@
 	"WHERE { "							\
 	"{ "								\
 		"?x a nco:Contact . "					\
+		"?x nco:hasPhoneNumber ?t . "				\
+		"?call a nmo:Call ; "					\
+		"nmo:from ?x ; "					\
+		"nmo:isSent false ; "					\
+		"nmo:isAnswered false . "				\
+	"} UNION { "							\
+		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?h . "				\
 		"?call a nmo:Call ; "					\
 		"nmo:from ?x ; "					\
@@ -158,15 +165,8 @@
 		"OPTIONAL { ?a nco:hasEmailAddress ?ew . } "		\
 		"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "		\
 		"OPTIONAL { ?a nco:org ?o . } "				\
-	"} UNION { "							\
-		"?x a nco:Contact . "					\
-		"?x nco:hasPhoneNumber ?t . "				\
-		"?call a nmo:Call ; "					\
-		"nmo:from ?x ; "					\
-		"nmo:isSent false ; "					\
-		"nmo:isAnswered false . "				\
 	"} "								\
-	"} ORDER BY DESC(nmo:receivedDate(?call)) "
+	"} GROUP BY ?call ORDER BY DESC(nmo:receivedDate(?call)) "
 
 #define MISSED_CALLS_LIST						\
 	"SELECT ?c nco:nameFamily(?c) "					\
@@ -221,6 +221,13 @@
 	"WHERE { "							\
 	"{ "								\
 		"?x a nco:Contact . "					\
+		"?x nco:hasPhoneNumber ?t . "				\
+		"?call a nmo:Call ; "					\
+		"nmo:from ?x ; "					\
+		"nmo:isSent false ; "					\
+		"nmo:isAnswered true . "				\
+	"} UNION { "							\
+		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?h . "				\
 		"?call a nmo:Call ; "					\
 		"nmo:from ?x ; "					\
@@ -251,15 +258,8 @@
 		"OPTIONAL { ?a nco:hasEmailAddress ?ew . } "		\
 		"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "		\
 		"OPTIONAL { ?a nco:org ?o . } "				\
-	"} UNION { "							\
-		"?x a nco:Contact . "					\
-		"?x nco:hasPhoneNumber ?t . "				\
-		"?call a nmo:Call ; "					\
-		"nmo:from ?x ; "					\
-		"nmo:isSent false ; "					\
-		"nmo:isAnswered true . "				\
 	"} "								\
-	"} ORDER BY DESC(nmo:receivedDate(?call)) "
+	"} GROUP BY ?call ORDER BY DESC(nmo:receivedDate(?call)) "
 
 #define INCOMING_CALLS_LIST						\
 	"SELECT ?c nco:nameFamily(?c) "					\
@@ -314,6 +314,12 @@
 	"WHERE { "							\
 	"{ "								\
 		"?x a nco:Contact . "					\
+		"?x nco:hasPhoneNumber ?t . "				\
+		"?call a nmo:Call ; "					\
+		"nmo:to ?x ; "						\
+		"nmo:isSent true . "					\
+	"} UNION { "							\
+		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?h . "				\
 		"?call a nmo:Call ; "					\
 		"nmo:to ?x ; "						\
@@ -342,14 +348,8 @@
 		"OPTIONAL { ?a nco:hasEmailAddress ?ew . } "		\
 		"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "		\
 		"OPTIONAL { ?a nco:org ?o . } "				\
-	"} UNION { "							\
-		"?x a nco:Contact . "					\
-		"?x nco:hasPhoneNumber ?t . "				\
-		"?call a nmo:Call ; "					\
-		"nmo:to ?x ; "						\
-		"nmo:isSent true . "					\
 	"} "								\
-	"} ORDER BY DESC(nmo:sentDate(?call)) "
+	"} GROUP BY ?call ORDER BY DESC(nmo:sentDate(?call)) "
 
 #define OUTGOING_CALLS_LIST						\
 	"SELECT ?c nco:nameFamily(?c) "					\
@@ -400,7 +400,12 @@
 	"nmo:isSent(?call) nmo:isAnswered(?call) ?x "			\
 	"WHERE { "							\
 	"{ "								\
-		"{ "							\
+		"?x a nco:Contact . "					\
+		"?x nco:hasPhoneNumber ?t . "				\
+		"?call a nmo:Call ; "					\
+		"nmo:to ?x ; "						\
+		"nmo:isSent true . "					\
+	"} UNION { "							\
 		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?h . "				\
 		"?call a nmo:Call ; "					\
@@ -416,7 +421,7 @@
 			"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "	\
 			"OPTIONAL { ?a nco:org ?o . } "			\
 		"} "							\
-		"} UNION { "						\
+	"} UNION { "							\
 		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?w . "				\
 		"?call a nmo:Call ; "					\
@@ -430,15 +435,13 @@
 		"OPTIONAL { ?a nco:hasEmailAddress ?ew . } "		\
 		"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "		\
 		"OPTIONAL { ?a nco:org ?o . } "				\
-		"} UNION { "						\
+	"} UNION { "							\
 		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?t . "				\
 		"?call a nmo:Call ; "					\
-		"nmo:to ?x ; "						\
-		"nmo:isSent true . "					\
-		"} "							\
+		"nmo:from ?x ; "					\
+		"nmo:isSent false . "					\
 	"} UNION { "							\
-		"{ "							\
 		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?h . "				\
 		"?call a nmo:Call ; "					\
@@ -454,7 +457,7 @@
 			"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "	\
 			"OPTIONAL { ?a nco:org ?o . } "			\
 		"} "							\
-		"} UNION { "						\
+	"} UNION { "							\
 		"?x a nco:Contact . "					\
 		"?x nco:hasPhoneNumber ?w . "				\
 		"?call a nmo:Call ; "					\
@@ -468,15 +471,8 @@
 		"OPTIONAL { ?a nco:hasEmailAddress ?ew . } "		\
 		"OPTIONAL { ?a nco:hasPostalAddress ?pw . } "		\
 		"OPTIONAL { ?a nco:org ?o . } "				\
-		"} UNION { "						\
-		"?x a nco:Contact . "					\
-		"?x nco:hasPhoneNumber ?t . "				\
-		"?call a nmo:Call ; "					\
-		"nmo:from ?x ; "					\
-		"nmo:isSent false . "					\
-		"} "							\
 	"} "								\
-	"} ORDER BY DESC(nmo:receivedDate(?call)) "
+	"} GROUP BY ?call ORDER BY DESC(nmo:receivedDate(?call)) "
 
 #define COMBINED_CALLS_LIST						\
 	"SELECT ?c nco:nameFamily(?c) nco:nameGiven(?c) "		\
-- 
1.6.3.3


[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