[rygel] media-export: Add function to count search result
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Add function to count search result
- Date: Mon, 7 Jun 2010 14:27:50 +0000 (UTC)
commit 8f97748bed6a91836f947ced4bb9f07dff5321cd
Author: Jens Georg <mail jensge org>
Date: Sun May 16 13:18:26 2010 +0200
media-export: Add function to count search result
This speeds up virtual folder creation by factor 30. Noticable speed
improvements on XBox music browsing
.../rygel-media-export-media-cache.vala | 71 ++++++++++++++++++++
.../rygel-media-export-query-container.vala | 3 +-
2 files changed, 72 insertions(+), 2 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 5794ca5..de47da6 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -181,6 +181,16 @@ public class Rygel.MediaExport.MediaCache : Object {
"o.title ASC " +
"LIMIT ?,?";
+ // The uris are joined in to be able to filter by "ref"
+ private const string GET_OBJECT_COUNT_BY_FILTER_STRING =
+ "SELECT COUNT(o.type_fk) FROM Object o " +
+ "JOIN Closure c ON o.upnp_id = c.descendant AND c.ancestor = ? " +
+ "JOIN meta_data m " +
+ "ON o.upnp_id = m.object_fk " +
+ "WHERE %s " +
+ "LIMIT ?,?";
+
+
private const string CHILDREN_COUNT_STRING =
"SELECT COUNT(upnp_id) FROM Object WHERE Object.parent = ?";
@@ -373,6 +383,67 @@ public class Rygel.MediaExport.MediaCache : Object {
max_objects);
}
+ public long get_object_count_by_search_expression (
+ SearchExpression? expression,
+ string container_id,
+ uint offset,
+ uint max_count)
+ throws Error {
+ var args = new GLib.ValueArray (0);
+ var filter = this.search_expression_to_sql (expression, args);
+
+ if (filter == null) {
+ return 0;
+ }
+
+ debug (_("Original search: %s"), expression.to_string ());
+ debug (_("Parsed search expression: %s"), filter);
+
+ for (int i = 0; i < args.n_values; i++) {
+ debug ("Arg %d: %s", i, args.get_nth (i).get_string ());
+ }
+
+ var max_objects = modify_limit (max_count);
+
+ return this.get_object_count_by_filter (filter,
+ args,
+ container_id,
+ offset,
+ max_objects);
+ }
+
+ public long get_object_count_by_filter (
+ string filter,
+ GLib.ValueArray args,
+ string container_id,
+ long offset,
+ long max_count)
+ throws Error {
+ GLib.Value v = container_id;
+ args.prepend (v);
+ v = offset;
+ args.append (v);
+ v = max_count;
+ args.append (v);
+ long count = 0;
+
+ debug ("%s %ld %ld", container_id, offset, max_count);
+ debug ("Parameters to bind: %u", args.n_values);
+
+ Database.RowCallback callback = (statement) => {
+ count = statement.column_int (0);
+
+ return false;
+ };
+
+ this.db.exec (GET_OBJECT_COUNT_BY_FILTER_STRING.printf (filter),
+ args.values,
+ callback);
+
+ return count;
+ }
+
+
public Gee.ArrayList<MediaObject> get_objects_by_filter (
string filter,
GLib.ValueArray args,
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 3a14a7a..8a776cc 100644
--- a/src/plugins/media-export/rygel-media-export-query-container.vala
+++ b/src/plugins/media-export/rygel-media-export-query-container.vala
@@ -120,12 +120,11 @@ internal class Rygel.MediaExport.QueryContainer : DBContainer {
private int count_children () {
try {
if (this.pattern == "") {
- var children = this.media_db.get_objects_by_search_expression (
+ return (int) this.media_db.get_object_count_by_search_expression (
this.expression,
"0",
0,
-1);
- return children.size;
} else {
int retval = 0;
var data = this.media_db.get_object_attribute_by_search_expression (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]