From 1b8c1d5969f471f5dd77c90c08250879acf7dffd Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Sun, 16 Oct 2011 15:20:06 +0200 Subject: [PATCH] core: Batch uris for thumbnail requests Previously it was only creating one thumbnail per browse request https://bugzilla.gnome.org/show_bug.cgi?id=661334 --- src/rygel/rygel-dbus-thumbnailer.vala | 92 ++++++++++++++++------------------- src/rygel/rygel-thumbnailer.vala | 2 +- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/rygel/rygel-dbus-thumbnailer.vala b/src/rygel/rygel-dbus-thumbnailer.vala index 5864763..acb30ee 100644 --- a/src/rygel/rygel-dbus-thumbnailer.vala +++ b/src/rygel/rygel-dbus-thumbnailer.vala @@ -18,6 +18,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +using Gee; + [DBus (name = "org.freedesktop.thumbnails.Thumbnailer1")] interface Tumbler : GLib.Object { public abstract async uint Queue (string[] uris, @@ -27,75 +29,65 @@ interface Tumbler : GLib.Object { uint handle) throws GLib.IOError, GLib.DBusError; - - public signal void Finished (uint handle); - public signal void Error (uint handle, - string[] failed_uris, - int error_code, - string message); } - internal class Rygel.DbusThumbnailer : GLib.Object { private Tumbler tumbler; - private bool is_running = false; - private string file_path; + private ArrayList uris; + private ArrayList mimes; + private uint timeout_id; + private string flavor; - const string THUMBNAILER_IFACE = "org.freedesktop.thumbnails.Thumbnailer1"; - const string THUMBNAILER_SERVICE = - "/org/freedesktop/thumbnails/Thumbnailer1"; + private const string THUMBNAILER_IFACE = + "org.freedesktop.thumbnails.Thumbnailer1"; + private const string THUMBNAILER_SERVICE = + "/org/freedesktop/thumbnails/Thumbnailer1"; - public signal void generated (string file_path); - public signal void error (string file_path, - int error_code, - string message); + private const uint THUMBNAIL_MAX_QUEUE_SIZE = 50; + public DbusThumbnailer (string flavor = "normal") throws GLib.IOError, + GLib.DBusError { + this.uris = new ArrayList (); + this.mimes = new ArrayList (); + this.timeout_id = 0; + this.flavor = flavor; - - public DbusThumbnailer () throws GLib.IOError, - GLib.DBusError{ this.tumbler = GLib.Bus.get_proxy_sync (BusType.SESSION, THUMBNAILER_IFACE, THUMBNAILER_SERVICE); - - tumbler.Finished.connect (on_finished); - tumbler.Error.connect (on_error); } - public async void create_thumbnail_task (string file_path, - string mime, - string flavor) { - string uris[1]; - string mimes[1]; + public void queue_thumbnail_task (string file_path, string mime) { + this.uris.add (file_path); + this.mimes.add (mime); - if (in_progress ()) { - return; + if (this.timeout_id != 0) { + Source.remove (this.timeout_id); } - this.is_running = true; - this.file_path = file_path; - - uris[0] = file_path; - mimes[0] = mime; - - try { - yield this.tumbler.Queue (uris, mimes, flavor, "default", 0); - } catch (Error error) { } + if (this.uris.size < THUMBNAIL_MAX_QUEUE_SIZE) { + // delay update to collect more thumbnail creation requests + this.timeout_id = Timeout.add (100, this.on_timeout); + } else { + // queue has grown quite large, flush directly + this.on_timeout (); + } } - public bool in_progress () { - return this.is_running; - } + private bool on_timeout () { + debug ("Queueing thumbnail creation for %d files", + this.uris.size); - private void on_finished (uint handle) { - generated (this.file_path); - this.is_running = false; - } + this.tumbler.Queue (this.uris.to_array (), + this.mimes.to_array (), + this.flavor, + "default", + 0); + + this.uris.clear (); + this.mimes.clear (); + this.timeout_id = 0; - private void on_error (uint handle, - string[] failed_uris, - int error_code, - string message) { - error (this.file_path, error_code, message); + return false; } } diff --git a/src/rygel/rygel-thumbnailer.vala b/src/rygel/rygel-thumbnailer.vala index af9eb34..c93c281 100644 --- a/src/rygel/rygel-thumbnailer.vala +++ b/src/rygel/rygel-thumbnailer.vala @@ -105,7 +105,7 @@ internal class Rygel.Thumbnailer : GLib.Object { // send a request to create thumbnail if it does not exist if ((this.thumbler != null) && (!file.query_exists ())) { - this.thumbler.create_thumbnail_task (uri, mime_type, "normal"); + this.thumbler.queue_thumbnail_task (uri, mime_type); } var info = file.query_info (FILE_ATTRIBUTE_ACCESS_CAN_READ + "," + -- 2.7.4