aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-04-11 14:41:18 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-04-11 14:41:18 -0500
commit2241aff419d1ccacc5c4807caf342dc1c86ceae4 (patch)
tree8bff817733bf36596e115c4ac50b868541a8f0e4
parentdf8bb67ba823f683fabe0564b1c7249a33614090 (diff)
downloadayatana-indicator-datetime-2241aff419d1ccacc5c4807caf342dc1c86ceae4.tar.gz
ayatana-indicator-datetime-2241aff419d1ccacc5c4807caf342dc1c86ceae4.tar.bz2
ayatana-indicator-datetime-2241aff419d1ccacc5c4807caf342dc1c86ceae4.zip
if we have a flood of EDS events coming in, wait a longer interval before requerying the EDS engine
-rw-r--r--src/engine-eds.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp
index c557857..c20731d 100644
--- a/src/engine-eds.cpp
+++ b/src/engine-eds.cpp
@@ -25,6 +25,7 @@
#include <libedataserver/libedataserver.h>
#include <algorithm> // std::sort()
+#include <ctime> // time()
#include <map>
#include <set>
@@ -144,16 +145,29 @@ private:
{
auto self = static_cast<Impl*>(gself);
self->m_rebuild_tag = 0;
+ self->m_rebuild_deadline = 0;
self->set_dirty_now();
return G_SOURCE_REMOVE;
}
void set_dirty_soon()
{
- static const int ARBITRARY_BATCH_MSEC = 200;
+ static constexpr int MIN_BATCH_SEC = 1;
+ static constexpr int MAX_BATCH_SEC = 60;
+ static_assert(MIN_BATCH_SEC <= MAX_BATCH_SEC, "bad boundaries");
- if (m_rebuild_tag == 0)
- m_rebuild_tag = g_timeout_add(ARBITRARY_BATCH_MSEC, set_dirty_now_static, this);
+ const auto now = time(nullptr);
+
+ if (m_rebuild_deadline == 0) // first pass
+ {
+ m_rebuild_deadline = now + MAX_BATCH_SEC;
+ m_rebuild_tag = g_timeout_add_seconds(MIN_BATCH_SEC, set_dirty_now_static, this);
+ }
+ else if (now < m_rebuild_deadline)
+ {
+ g_source_remove (m_rebuild_tag);
+ m_rebuild_tag = g_timeout_add_seconds(MIN_BATCH_SEC, set_dirty_now_static, this);
+ }
}
static void on_source_registry_ready(GObject* /*source*/, GAsyncResult* res, gpointer gself)
@@ -496,6 +510,7 @@ private:
GCancellable* m_cancellable = nullptr;
ESourceRegistry* m_source_registry = nullptr;
guint m_rebuild_tag = 0;
+ time_t m_rebuild_deadline = 0;
};
/***