[evolution-data-server] Bug 775699 - Only latest 100 tasks downloaded from the Google ][



commit afdb2bce1464d2a8576bc15a33855d154923332c
Author: Milan Crha <mcrha redhat com>
Date:   Mon Feb 27 11:01:37 2017 +0100

    Bug 775699 - Only latest 100 tasks downloaded from the Google ][

 CMakeLists.txt                                     |    5 +-
 .../backends/gtasks/e-cal-backend-gtasks.c         |   55 +++++++++++++++----
 2 files changed, 45 insertions(+), 15 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e85182..becb360 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -783,9 +783,8 @@ if(ENABLE_GOOGLE)
 
        CHECK_C_SOURCE_COMPILES("#include <gdata/gdata.h>
                                int main(void) {
-                                       const gchar *next_page_token;
-                                       next_page_token = gdata_feed_get_next_page_token (NULL);
-                                       gdata_tasks_query_set_page_token (NULL, next_page_token);
+                                       gdata_feed_get_next_page_token (NULL);
+                                       gdata_query_next_page (NULL);
                                        return 0;
                                }" HAVE_LIBGDATA_TASKS_PAGINATION_FUNCTIONS)
 
diff --git a/src/calendar/backends/gtasks/e-cal-backend-gtasks.c 
b/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
index 8c3aade..9a12a95 100644
--- a/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
+++ b/src/calendar/backends/gtasks/e-cal-backend-gtasks.c
@@ -34,8 +34,13 @@
 #define EDC_ERROR_EX(_code, _msg) e_data_cal_create_error (_code, _msg)
 
 #define GTASKS_KEY_LAST_UPDATED "last-updated"
+#define GTASKS_KEY_VERSION     "version"
 #define X_EVO_GTASKS_SELF_LINK "X-EVOLUTION-GTASKS-SELF-LINK"
 
+/* Current data version; when doesn't match with the stored,
+   then fetches everything again. */
+#define GTASKS_DATA_VERSION    "1"
+
 #define PROPERTY_LOCK(_gtasks) g_mutex_lock (&(_gtasks)->priv->property_mutex)
 #define PROPERTY_UNLOCK(_gtasks) g_mutex_unlock (&(_gtasks)->priv->property_mutex)
 
@@ -53,6 +58,26 @@ struct _ECalBackendGTasksPrivate {
 
 G_DEFINE_TYPE (ECalBackendGTasks, e_cal_backend_gtasks, E_TYPE_CAL_BACKEND)
 
+static gboolean
+ecb_gtasks_check_data_version_locked (ECalBackendGTasks *gtasks)
+{
+       const gchar *key;
+       gboolean data_version_correct;
+
+       g_return_val_if_fail (E_IS_CAL_BACKEND_GTASKS (gtasks), FALSE);
+
+       key = e_cal_backend_store_get_key_value (gtasks->priv->store, GTASKS_KEY_VERSION);
+       data_version_correct = g_strcmp0 (key, GTASKS_DATA_VERSION) == 0;
+
+       return data_version_correct;
+}
+
+static void
+ecb_gtasks_store_data_version_locked (ECalBackendGTasks *gtasks)
+{
+       e_cal_backend_store_put_key_value (gtasks->priv->store, GTASKS_KEY_VERSION, GTASKS_DATA_VERSION);
+}
+
 static GCancellable *
 ecb_gtasks_ref_cancellable (ECalBackendGTasks *gtasks)
 {
@@ -436,9 +461,13 @@ ecb_gtasks_update_thread (gpointer user_data)
 
        PROPERTY_LOCK (gtasks);
 
-       key = e_cal_backend_store_get_key_value (gtasks->priv->store, GTASKS_KEY_LAST_UPDATED);
-       if (!key || !g_time_val_from_iso8601 (key, &last_updated))
+       if (ecb_gtasks_check_data_version_locked (gtasks)) {
+               key = e_cal_backend_store_get_key_value (gtasks->priv->store, GTASKS_KEY_LAST_UPDATED);
+               if (!key || !g_time_val_from_iso8601 (key, &last_updated))
+                       last_updated.tv_sec = 0;
+       } else {
                last_updated.tv_sec = 0;
+       }
 
        PROPERTY_UNLOCK (gtasks);
 
@@ -462,7 +491,6 @@ ecb_gtasks_update_thread (gpointer user_data)
 
 #ifdef HAVE_LIBGDATA_TASKS_PAGINATION_FUNCTIONS
        while (feed && !g_cancellable_is_cancelled (cancellable) && !local_error) {
-               const gchar *next_page_token;
 #else
        if (feed) {
 #endif
@@ -538,11 +566,10 @@ ecb_gtasks_update_thread (gpointer user_data)
                PROPERTY_UNLOCK (gtasks);
 
 #ifdef HAVE_LIBGDATA_TASKS_PAGINATION_FUNCTIONS
-               next_page_token = gdata_feed_get_next_page_token (feed);
-               if (!next_page_token || !*next_page_token)
+               if (!gdata_feed_get_entries (feed))
                        break;
 
-               gdata_tasks_query_set_page_token (tasks_query, next_page_token);
+               gdata_query_next_page (GDATA_QUERY (tasks_query));
 
                g_clear_object (&feed);
 
@@ -566,6 +593,8 @@ ecb_gtasks_update_thread (gpointer user_data)
                e_cal_backend_store_put_key_value (gtasks->priv->store, GTASKS_KEY_LAST_UPDATED, strtm);
                g_free (strtm);
 
+               ecb_gtasks_store_data_version_locked (gtasks);
+
                PROPERTY_UNLOCK (gtasks);
        }
 
@@ -614,14 +643,16 @@ ecb_gtasks_start_update (ECalBackendGTasks *gtasks)
                                taskslist_time = gdata_entry_get_updated (entry);
 
                                if (taskslist_time > 0) {
-                                       GTimeVal stored;
-                                       const gchar *key;
-
                                        PROPERTY_LOCK (gtasks);
 
-                                       key = e_cal_backend_store_get_key_value (gtasks->priv->store, 
GTASKS_KEY_LAST_UPDATED);
-                                       if (key && g_time_val_from_iso8601 (key, &stored))
-                                               changed = taskslist_time != stored.tv_sec;
+                                       if (ecb_gtasks_check_data_version_locked (gtasks)) {
+                                               GTimeVal stored;
+                                               const gchar *key;
+
+                                               key = e_cal_backend_store_get_key_value (gtasks->priv->store, 
GTASKS_KEY_LAST_UPDATED);
+                                               if (key && g_time_val_from_iso8601 (key, &stored))
+                                                       changed = taskslist_time != stored.tv_sec;
+                                       }
 
                                        PROPERTY_UNLOCK (gtasks);
                                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]