From a093dead8a2b433965e41af4ae691b2f9c2506c8 Mon Sep 17 00:00:00 2001 From: Rafal Michalski Date: Wed, 27 Oct 2010 09:19:21 +0200 Subject: [PATCH] obexd: Optimize call history queries This patch optimizes call history queries - now there is no redundant results of invoking them. --- obexd/plugins/phonebook-tracker.c | 74 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/obexd/plugins/phonebook-tracker.c b/obexd/plugins/phonebook-tracker.c index 3367e49e0..e037677b5 100644 --- a/obexd/plugins/phonebook-tracker.c +++ b/obexd/plugins/phonebook-tracker.c @@ -127,6 +127,13 @@ "nmo:isSent(?call) nmo:isAnswered(?call) ?x " \ "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 ; " \ @@ -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) " \ @@ -220,6 +220,13 @@ "nmo:isSent(?call) nmo:isAnswered(?call) ?x " \ "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 ; " \ @@ -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) " \ @@ -313,6 +313,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 ; " \ @@ -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) " \ -- 2.47.3