diff options
author | Milan Crha <mcrha@redhat.com> | 2012-09-06 20:34:46 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2012-09-06 20:34:46 +0800 |
commit | f568645ff6bc2a66db8ca7dc0b483569199d0e87 (patch) | |
tree | bf900e7291a1ff50b4471e11956dbd9bda842fa8 | |
parent | 3451671ce9296afda4135670c65e8df3fffe02b2 (diff) | |
download | gsoc2013-evolution-f568645ff6bc2a66db8ca7dc0b483569199d0e87.tar.gz gsoc2013-evolution-f568645ff6bc2a66db8ca7dc0b483569199d0e87.tar.zst gsoc2013-evolution-f568645ff6bc2a66db8ca7dc0b483569199d0e87.zip |
Bug #679382 - Saving attachments takes too long, maxes CPU usage
-rw-r--r-- | widgets/misc/e-attachment.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/widgets/misc/e-attachment.c b/widgets/misc/e-attachment.c index b83bf1ce41..315b012b2d 100644 --- a/widgets/misc/e-attachment.c +++ b/widgets/misc/e-attachment.c @@ -66,6 +66,7 @@ struct _EAttachmentPrivate { guint emblem_timeout_id; gchar *disposition; gint percent; + gint64 last_percent_notify; /* to avoid excessive notifications */ guint can_show : 1; guint loading : 1; @@ -415,6 +416,7 @@ attachment_set_loading (EAttachment *attachment, attachment->priv->percent = 0; attachment->priv->loading = loading; + attachment->priv->last_percent_notify = 0; g_object_freeze_notify (G_OBJECT (attachment)); g_object_notify (G_OBJECT (attachment), "percent"); @@ -434,6 +436,7 @@ attachment_set_saving (EAttachment *attachment, { attachment->priv->percent = 0; attachment->priv->saving = saving; + attachment->priv->last_percent_notify = 0; g_object_freeze_notify (G_OBJECT (attachment)); g_object_notify (G_OBJECT (attachment), "percent"); @@ -446,14 +449,24 @@ attachment_progress_cb (goffset current_num_bytes, goffset total_num_bytes, EAttachment *attachment) { + gint new_percent; + /* Avoid dividing by zero. */ if (total_num_bytes == 0) return; - attachment->priv->percent = - (current_num_bytes * 100) / total_num_bytes; + /* do not notify too often, 5 times per second is sufficient */ + if (g_get_monotonic_time () - attachment->priv->last_percent_notify < 200000) + return; - g_object_notify (G_OBJECT (attachment), "percent"); + attachment->priv->last_percent_notify = g_get_monotonic_time (); + + new_percent = (current_num_bytes * 100) / total_num_bytes; + + if (new_percent != attachment->priv->percent) { + attachment->priv->percent = new_percent; + g_object_notify (G_OBJECT (attachment), "percent"); + } } static gboolean |