[rygel] media-export: Speed up "derivedFrom" searches



commit 27a268cb5ba2fe4171df07538db8d7a2877b7a9a
Author: Jens Georg <mail jensge org>
Date:   Sun Nov 28 01:21:06 2010 +0100

    media-export: Speed up "derivedFrom" searches

 .../media-export/rygel-media-export-database.vala  |   38 +++-----------------
 .../rygel-media-export-media-cache.vala            |   12 +++---
 2 files changed, 11 insertions(+), 39 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-database.vala b/src/plugins/media-export/rygel-media-export-database.vala
index 373fa9c..e3eb67f 100644
--- a/src/plugins/media-export/rygel-media-export-database.vala
+++ b/src/plugins/media-export/rygel-media-export-database.vala
@@ -43,29 +43,9 @@ internal class Rygel.MediaExport.Database : Object {
      */
     public delegate bool RowCallback (Sqlite.Statement stmt);
 
-    private static void utf8_has_prefix (Sqlite.Context context,
-                                         Sqlite.Value[] args)
-                                         requires (args.length == 2) {
-        if (args[0].to_text () == null ||
-            args[1].to_text () == null) {
-            context.result_int (0);
-
-            return;
-        }
-
-        var stra = args[0].to_text ().casefold ();
-        var strb = args[1].to_text ().casefold ();
-
-        if (stra.has_prefix (strb)) {
-            context.result_int (1);
-        } else {
-            context.result_int (0);
-        }
-    }
-
-    private static void utf8_like (Sqlite.Context context,
-                                   Sqlite.Value[] args)
-                                   requires (args.length == 2) {
+    private static void utf8_contains (Sqlite.Context context,
+                                       Sqlite.Value[] args)
+                                       requires (args.length == 2) {
         if (args[1].to_text() == null) {
            context.result_int (0);
 
@@ -73,7 +53,6 @@ internal class Rygel.MediaExport.Database : Object {
         }
 
         var pattern = Regex.escape_string (args[0].to_text ());
-        pattern = pattern.replace("%", ".*").replace ("_", ".");
         if (Regex.match_simple (pattern,
                                 args[1].to_text (),
                                 RegexCompileFlags.CASELESS)) {
@@ -121,19 +100,12 @@ internal class Rygel.MediaExport.Database : Object {
         this.db.exec ("PRAGMA synchronous = OFF");
         this.db.exec ("PRAGMA temp_store = MEMORY");
         this.db.exec ("PRAGMA count_changes = OFF");
-        this.db.create_function ("like",
-                                 2,
-                                 Sqlite.UTF8,
-                                 null,
-                                 Database.utf8_like,
-                                 null,
-                                 null);
 
-        this.db.create_function ("has_prefix",
+        this.db.create_function ("contains",
                                  2,
                                  Sqlite.UTF8,
                                  null,
-                                 Database.utf8_has_prefix,
+                                 Database.utf8_contains,
                                  null,
                                  null);
 
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index a101941..cd6c7ed 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -761,16 +761,16 @@ public class Rygel.MediaExport.MediaCache : Object {
                                         (exp.op, column, collate);
                 break;
             case SearchCriteriaOp.CONTAINS:
-                operator = new SqlOperator ("LIKE", column);
-                v = "%%%s%%".printf (exp.operand2);
+                operator = new SqlFunction ("contains", column);
+                v = exp.operand2;
                 break;
             case SearchCriteriaOp.DOES_NOT_CONTAIN:
-                operator = new SqlOperator ("NOT LIKE", column);
-                v = "%%%s%%".printf (exp.operand2);
+                operator = new SqlFunction ("NOT contains", column);
+                v = exp.operand2;
                 break;
             case SearchCriteriaOp.DERIVED_FROM:
-                operator = new SqlFunction ("has_prefix", column);
-                v = exp.operand2;
+                operator = new SqlOperator ("LIKE", column);
+                v = "%s%%".printf (exp.operand2);
                 break;
             default:
                 warning ("Unsupported op %d", exp.op);



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