[rygel] media-export: Only query for non-empty meta-data



commit e25f075c019b64de77f433bcc51b008fe920106a
Author: Jens Georg <mail jensge org>
Date:   Sat Jul 24 20:36:09 2010 +0300

    media-export: Only query for non-empty meta-data
    
    Previously a null check was in place in every function using this. Now
    the database filters the null columns itself.

 .../rygel-media-export-media-cache.vala            |   22 ++++++++++++-------
 .../rygel-media-export-query-container.vala        |   13 +----------
 2 files changed, 15 insertions(+), 20 deletions(-)
---
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 3c3a0a2..7c17c17 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -202,8 +202,8 @@ public class Rygel.MediaExport.MediaCache : Object {
     "SELECT upnp_id FROM OBJECT WHERE parent = ?";
 
     private const string GET_META_DATA_COLUMN_STRING =
-    "SELECT DISTINCT %s FROM meta_data AS m %s " +
-        "ORDER BY %s LIMIT ?,?";
+    "SELECT DISTINCT %s FROM meta_data AS m " +
+        "WHERE %s IS NOT NULL %s ORDER BY %s LIMIT ?,?";
 
     public void remove_by_id (string id) throws DatabaseError {
         GLib.Value[] values = { id };
@@ -704,14 +704,18 @@ public class Rygel.MediaExport.MediaCache : Object {
         return children;
     }
 
-    private string translate_search_expression (SearchExpression? expression,
-                                                ValueArray        args)
-                                                throws Error {
+    private string translate_search_expression (
+                                        SearchExpression? expression,
+                                        ValueArray        args,
+                                        string            prefix = "WHERE")
+                                        throws Error {
         if (expression == null) {
             return "";
         }
 
-        return " WHERE " + this.search_expression_to_sql (expression, args);
+        var filter = this.search_expression_to_sql (expression, args);
+
+        return " %s %s".printf (prefix, filter);
     }
 
     private string? search_expression_to_sql (SearchExpression? expression,
@@ -873,7 +877,7 @@ public class Rygel.MediaExport.MediaCache : Object {
             return true;
         };
 
-        var sql = GET_META_DATA_COLUMN_STRING.printf (column, filter, column);
+        var sql = GET_META_DATA_COLUMN_STRING.printf (column, column, filter, column);
         this.db.exec (sql, args.values, callback);
 
         return data;
@@ -886,7 +890,9 @@ public class Rygel.MediaExport.MediaCache : Object {
                                         long              max_count)
                                         throws Error {
         var args = new ValueArray (0);
-        var filter = this.translate_search_expression (expression, args);
+        var filter = this.translate_search_expression (expression,
+                                                       args,
+                                                       "AND");
 
         debug ("Parsed filter: %s", filter);
 
diff --git a/src/plugins/media-export/rygel-media-export-query-container.vala b/src/plugins/media-export/rygel-media-export-query-container.vala
index f2f1586..717c6ed 100644
--- a/src/plugins/media-export/rygel-media-export-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-query-container.vala
@@ -124,20 +124,13 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
                                         this.expression,
                                         "0");
             } else {
-                int retval = 0;
                 var data = this.media_db.get_object_attribute_by_search_expression (
                                         this.attribute,
                                         this.expression,
                                         0,
                                         -1);
 
-                foreach (var meta_data in data) {
-                    if (meta_data != null) {
-                        retval++;
-                    }
-                }
-
-                return retval;
+                return data.size;
             }
         } catch (Error e) {
             return 0;
@@ -216,10 +209,6 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
                                         offset,
                                         max_objects);
             foreach (var meta_data in data) {
-                if (meta_data == null) {
-                    continue;
-                }
-
                 var new_id = Uri.escape_string (meta_data, "", true);
                 // pattern contains URL escaped text. This means it might
                 // contain '%' chars which will makes sprintf crash



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