[rygel] core: Limit the search results



commit f8c6731340f9c86742d12cacd9590111af047059
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Nov 5 19:39:59 2009 +0200

    core: Limit the search results
    
    This should improve performance of search in general a lot but it
    depends on what slice in the search results the client is interested in.
    If it asks for the last slice, there will be no performance improvements
    to that search request because of this change. During an incremental
    search (which all clients should be doing), the first few search results
    will be extremely fast and we all know that this *will* effectively fool
    the end-user. :)

 src/rygel/rygel-media-container.vala |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/src/rygel/rygel-media-container.vala b/src/rygel/rygel-media-container.vala
index 8f05b2c..59f4eab 100644
--- a/src/rygel/rygel-media-container.vala
+++ b/src/rygel/rygel-media-container.vala
@@ -110,7 +110,19 @@ public abstract class Rygel.MediaContainer : MediaObject {
                                         throws Error {
         var result = new ArrayList<MediaObject> ();
 
-        var children = yield this.get_children (0, uint.MAX, cancellable);
+        var children = yield this.get_children (0,
+                                                this.child_count,
+                                                cancellable);
+
+        // The maximum number of results we need to be able to slice-out
+        // the needed portion from it.
+        uint limit;
+        if (offset > 0 || max_count > 0) {
+            limit = offset + max_count;
+        } else {
+            limit = 0; // No limits on searches
+        }
+
         foreach (var child in children) {
             if (child is MediaContainer) {
                 // First search inside the child container
@@ -119,7 +131,7 @@ public abstract class Rygel.MediaContainer : MediaObject {
 
                 var child_result = yield container.search (expression,
                                                            0,
-                                                           0,
+                                                           limit,
                                                            out tmp,
                                                            cancellable);
 
@@ -130,12 +142,16 @@ public abstract class Rygel.MediaContainer : MediaObject {
             if (expression.satisfied_by (child)) {
                 result.add (child);
             }
+
+            if (limit > 0 && limit <= result.size) {
+                break;
+            }
         }
 
         total_matches = result.size;
 
         // See if we need to slice the results
-        if (total_matches > 0 && (offset != 0 || max_count != 0)) {
+        if (total_matches > 0 && limit > 0) {
             uint start;
             uint stop;
 



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