aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-04-15 22:25:28 +0000
committerCI bot <ps-jenkins@lists.canonical.com>2014-04-15 22:25:28 +0000
commitc376385ec86eecb788f0f5f94148a680c1ff4f20 (patch)
treeafa8e8a614b8d42afa5fe0f2b51ce34ab72e5292
parentdf8bb67ba823f683fabe0564b1c7249a33614090 (diff)
parent61af48e621e774b774f9c7f61e8a972ab8201f15 (diff)
downloadayatana-indicator-datetime-c376385ec86eecb788f0f5f94148a680c1ff4f20.tar.gz
ayatana-indicator-datetime-c376385ec86eecb788f0f5f94148a680c1ff4f20.tar.bz2
ayatana-indicator-datetime-c376385ec86eecb788f0f5f94148a680c1ff4f20.zip
If there's a large batch of EDS events coming in, try to wait until the event storm has passed before running our requery. Fixes: 1306112
-rw-r--r--include/datetime/appointment.h2
-rw-r--r--src/appointment.cpp1
-rw-r--r--src/engine-eds.cpp163
-rw-r--r--tests/manual-test-snap.cpp2
4 files changed, 75 insertions, 93 deletions
diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h
index a5283c9..4778293 100644
--- a/include/datetime/appointment.h
+++ b/include/datetime/appointment.h
@@ -39,8 +39,6 @@ public:
std::string summary;
std::string url;
std::string uid;
- bool is_event = false;
- bool is_daily = false;
bool has_alarms = false;
DateTime begin;
DateTime end;
diff --git a/src/appointment.cpp b/src/appointment.cpp
index 6e742c3..98cc062 100644
--- a/src/appointment.cpp
+++ b/src/appointment.cpp
@@ -33,7 +33,6 @@ bool Appointment::operator==(const Appointment& that) const
&& (summary==that.summary)
&& (url==that.url)
&& (uid==that.uid)
- && (is_event==that.is_event)
&& (has_alarms==that.has_alarms)
&& (begin==that.begin)
&& (end==that.end);
diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp
index c557857..da93206 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)
@@ -272,6 +286,7 @@ private:
if (e_cal_client_get_view_finish (E_CAL_CLIENT(client), res, &view, &error))
{
// add the view to our collection
+ e_cal_client_view_set_flags(view, E_CAL_CLIENT_VIEW_FLAGS_NONE, NULL);
e_cal_client_view_start(view, &error);
g_debug("got a view for %s", e_cal_client_get_local_attachment_store(E_CAL_CLIENT(client)));
auto self = static_cast<Impl*>(gself);
@@ -386,14 +401,6 @@ private:
}
};
- struct UrlSubtask
- {
- std::shared_ptr<Task> task;
- Appointment appointment;
- UrlSubtask(const std::shared_ptr<Task>& task_in, const Appointment& appointment_in):
- task(task_in), appointment(appointment_in) {}
- };
-
static gboolean
my_get_appointments_foreach(ECalComponent* component,
time_t begin,
@@ -405,89 +412,68 @@ private:
if ((vtype == E_CAL_COMPONENT_EVENT) || (vtype == E_CAL_COMPONENT_TODO))
{
- const gchar* uid = nullptr;
- e_cal_component_get_uid(component, &uid);
-
- auto status = ICAL_STATUS_NONE;
- e_cal_component_get_status(component, &status);
-
- if ((uid != nullptr) &&
- (status != ICAL_STATUS_COMPLETED) &&
- (status != ICAL_STATUS_CANCELLED))
- {
- Appointment appointment;
-
- /* Determine whether this is a recurring event.
- NB: icalrecurrencetype supports complex recurrence patterns;
- however, since design only allows daily recurrence,
- that's all we support here. */
- GSList * recur_list;
- e_cal_component_get_rrule_list(component, &recur_list);
- for (auto l=recur_list; l!=nullptr; l=l->next)
- {
- const auto recur = static_cast<struct icalrecurrencetype*>(l->data);
- appointment.is_daily |= ((recur->freq == ICAL_DAILY_RECURRENCE)
- && (recur->interval == 1));
- }
- e_cal_component_free_recur_list(recur_list);
-
- ECalComponentText text;
- text.value = nullptr;
- e_cal_component_get_summary(component, &text);
- if (text.value)
- appointment.summary = text.value;
-
- appointment.begin = DateTime(begin);
- appointment.end = DateTime(end);
- appointment.color = subtask->color;
- appointment.is_event = vtype == E_CAL_COMPONENT_EVENT;
- appointment.uid = uid;
-
- GList * alarm_uids = e_cal_component_get_alarm_uids(component);
- appointment.has_alarms = alarm_uids != nullptr;
- cal_obj_uid_list_free(alarm_uids);
-
- e_cal_client_get_attachment_uris(subtask->client,
- uid,
- nullptr,
- subtask->task->p->m_cancellable,
- on_appointment_uris_ready,
- new UrlSubtask(subtask->task, appointment));
- }
- }
+ const gchar* uid = nullptr;
+ e_cal_component_get_uid(component, &uid);
- return G_SOURCE_CONTINUE;
- }
+ auto status = ICAL_STATUS_NONE;
+ e_cal_component_get_status(component, &status);
- static void on_appointment_uris_ready(GObject* client, GAsyncResult* res, gpointer gsubtask)
- {
- auto subtask = static_cast<UrlSubtask*>(gsubtask);
-
- GSList * uris = nullptr;
- GError * error = nullptr;
- e_cal_client_get_attachment_uris_finish(E_CAL_CLIENT(client), res, &uris, &error);
- if (error != nullptr)
- {
- if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
- !g_error_matches(error, E_CLIENT_ERROR, E_CLIENT_ERROR_NOT_SUPPORTED))
+ if ((uid != nullptr) &&
+ (status != ICAL_STATUS_COMPLETED) &&
+ (status != ICAL_STATUS_CANCELLED))
{
- g_warning("Error getting appointment uris: %s", error->message);
+ Appointment appointment;
+
+ ECalComponentText text;
+ text.value = nullptr;
+ e_cal_component_get_summary(component, &text);
+ if (text.value)
+ appointment.summary = text.value;
+
+ appointment.begin = DateTime(begin);
+ appointment.end = DateTime(end);
+ appointment.color = subtask->color;
+ appointment.uid = uid;
+
+ // if the component has display alarms that have a url,
+ // use the first one as our Appointment.url
+ auto alarm_uids = e_cal_component_get_alarm_uids(component);
+ appointment.has_alarms = alarm_uids != nullptr;
+ for(auto walk=alarm_uids; appointment.url.empty() && walk!=nullptr; walk=walk->next)
+ {
+ auto alarm = e_cal_component_get_alarm(component, static_cast<const char*>(walk->data));
+
+ ECalComponentAlarmAction action;
+ e_cal_component_alarm_get_action(alarm, &action);
+ if (action == E_CAL_COMPONENT_ALARM_DISPLAY)
+ {
+ icalattach* attach = nullptr;
+ e_cal_component_alarm_get_attach(alarm, &attach);
+ if (attach != nullptr)
+ {
+ if (icalattach_get_is_url (attach))
+ {
+ const char* url = icalattach_get_url(attach);
+ if (url != nullptr)
+ appointment.url = url;
+ }
+
+ icalattach_unref(attach);
+ }
+ }
+
+ e_cal_component_alarm_free(alarm);
+ }
+ cal_obj_uid_list_free(alarm_uids);
+
+ g_debug("adding appointment '%s' '%s'", appointment.summary.c_str(), appointment.url.c_str());
+ subtask->task->appointments.push_back(appointment);
}
-
- g_error_free(error);
- }
- else if (uris != nullptr)
- {
- subtask->appointment.url = (const char*) uris->data; // copy the first URL
- g_debug("found url '%s' for appointment '%s'", subtask->appointment.url.c_str(), subtask->appointment.summary.c_str());
- e_client_util_free_string_slist(uris);
}
-
- g_debug("adding appointment '%s' '%s'", subtask->appointment.summary.c_str(), subtask->appointment.url.c_str());
- subtask->task->appointments.push_back(subtask->appointment);
- delete subtask;
+
+ return G_SOURCE_CONTINUE;
}
-
+
EdsEngine& m_owner;
core::Signal<> m_changed;
std::set<ESource*> m_sources;
@@ -496,6 +482,7 @@ private:
GCancellable* m_cancellable = nullptr;
ESourceRegistry* m_source_registry = nullptr;
guint m_rebuild_tag = 0;
+ time_t m_rebuild_deadline = 0;
};
/***
diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp
index 51556cd..16e606a 100644
--- a/tests/manual-test-snap.cpp
+++ b/tests/manual-test-snap.cpp
@@ -36,8 +36,6 @@ int main()
a.summary = "Alarm";
a.url = "alarm:///hello-world";
a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
- a.is_event = false;
- a.is_daily = false;
a.has_alarms = true;
auto begin = g_date_time_new_local(2014,12,25,0,0,0);
auto end = g_date_time_add_full(begin,0,0,1,0,0,-1);