[rygel] tracker: Optimize handling of invalid searches



commit 2c0167d581c64952edb419b4905c6256ab947052
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Sep 28 16:21:46 2010 +0300

    tracker: Optimize handling of invalid searches
    
    SearchContainer now almost always deals with every simple (relation
    expression) searches on its own. This speeds-up lots of search requests
    since now dbus queries to tracker are only launched in the particular
    SearchContainer in which they actually apply.

 .../tracker/rygel-tracker-search-container.vala    |   48 +++++++++----------
 1 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-search-container.vala b/src/plugins/tracker/rygel-tracker-search-container.vala
index 3026ea4..ef71a4e 100644
--- a/src/plugins/tracker/rygel-tracker-search-container.vala
+++ b/src/plugins/tracker/rygel-tracker-search-container.vala
@@ -125,10 +125,8 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
                                                 Cancellable?      cancellable)
                                                 throws GLib.Error {
         var results = new MediaObjects ();
-        var query = this.create_query (expression,
-                                       (int) offset,
-                                       (int) max_count);
-        if (query == null) {
+
+        if (expression == null || !(expression is RelationalExpression)) {
             return yield base.search (expression,
                                       offset,
                                       max_count,
@@ -136,16 +134,21 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
                                       cancellable);
         }
 
-        yield query.execute (this.resources);
+        var query = this.create_query (expression as RelationalExpression,
+                                       (int) offset,
+                                       (int) max_count);
+        if (query != null) {
+            yield query.execute (this.resources);
 
-        /* Iterate through all items */
-        for (uint i = 0; i < query.result.length[0]; i++) {
-            var id = this.create_child_id_for_urn (query.result[i, 0]);
-            var uri = query.result[i, 1];
-            string[] metadata = this.slice_strvv_tail (query.result, i, 2);
+            /* Iterate through all items */
+            for (uint i = 0; i < query.result.length[0]; i++) {
+                var id = this.create_child_id_for_urn (query.result[i, 0]);
+                var uri = query.result[i, 1];
+                string[] metadata = this.slice_strvv_tail (query.result, i, 2);
 
-            var item = this.item_factory.create (id, uri, this, metadata);
-            results.add (item);
+                var item = this.item_factory.create (id, uri, this, metadata);
+                results.add (item);
+            }
         }
 
         total_matches = results.size;
@@ -191,27 +194,22 @@ public class Rygel.Tracker.SearchContainer : Rygel.MediaContainer {
         }
     }
 
-    private SelectionQuery? create_query (SearchExpression? expression,
-                                          int               offset,
-                                          int               max_count) {
-        if (expression == null || !(expression is RelationalExpression)) {
-            return null;
-        }
-
-        var rel_expression = expression as RelationalExpression;
-        if (rel_expression.operand1 == "upnp:class" &&
-            rel_expression.operand2.has_prefix (MediaContainer.UPNP_CLASS)) {
+    private SelectionQuery? create_query (RelationalExpression? expression,
+                                          int                   offset,
+                                          int                   max_count) {
+        if (expression.operand1 == "upnp:class" &&
+            expression.operand2.has_prefix (MediaContainer.UPNP_CLASS)) {
             return null;
         }
 
         var query = new SelectionQuery.clone (this.query);
 
-        if (rel_expression.operand1 == "@parentID") {
-            if (!rel_expression.compare_string (this.id)) {
+        if (expression.operand1 == "@parentID") {
+            if (!expression.compare_string (this.id)) {
                 return null;
             }
         } else {
-            var filter = create_filter_for_child (rel_expression);
+            var filter = create_filter_for_child (expression);
             if (filter != null) {
                 query.filters.insert (0, filter);
             } else {



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