[evolution-data-server] Bug 793927 - [Google book] Do not use URI as contact UID
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 793927 - [Google book] Do not use URI as contact UID
- Date: Tue, 29 May 2018 15:11:31 +0000 (UTC)
commit 85a4ce2def79a6591e8272ca1fa0d53b9ff14a83
Author: Milan Crha <mcrha redhat com>
Date: Tue May 29 17:11:53 2018 +0200
Bug 793927 - [Google book] Do not use URI as contact UID
.../backends/google/e-book-backend-google.c | 54 +++++++++++++++++++++-
.../backends/google/e-book-google-utils.c | 20 +++++++-
.../backends/google/e-book-google-utils.h | 2 +
3 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/src/addressbook/backends/google/e-book-backend-google.c
b/src/addressbook/backends/google/e-book-backend-google.c
index 78492e55b..c6671005c 100644
--- a/src/addressbook/backends/google/e-book-backend-google.c
+++ b/src/addressbook/backends/google/e-book-backend-google.c
@@ -35,6 +35,9 @@
#define URI_GET_CONTACTS "https://www.google.com/m8/feeds/contacts/default/full"
+/* Local cache data version. Change it to re-download whole book content */
+#define EBB_GOOGLE_DATA_VERSION 2
+
G_DEFINE_TYPE (EBookBackendGoogle, e_book_backend_google, E_TYPE_BOOK_META_BACKEND)
struct _EBookBackendGooglePrivate {
@@ -451,6 +454,7 @@ ebb_google_get_changes_sync (EBookMetaBackend *meta_backend,
GTimeVal last_updated;
GDataFeed *feed;
GDataContactsQuery *contacts_query;
+ GHashTable *known_uids = NULL;
GError *local_error = NULL;
g_return_val_if_fail (E_IS_BOOK_BACKEND_GOOGLE (meta_backend), FALSE);
@@ -470,6 +474,10 @@ ebb_google_get_changes_sync (EBookMetaBackend *meta_backend,
book_cache = e_book_meta_backend_ref_cache (meta_backend);
+ /* Download everything when the local data version mismatches */
+ if (e_cache_get_key_int (E_CACHE (book_cache), "google-data-version", NULL) !=
EBB_GOOGLE_DATA_VERSION)
+ last_sync_tag = NULL;
+
if (!last_sync_tag ||
!g_time_val_from_iso8601 (last_sync_tag, &last_updated)) {
last_updated.tv_sec = 0;
@@ -496,6 +504,26 @@ ebb_google_get_changes_sync (EBookMetaBackend *meta_backend,
if (feed && !g_cancellable_is_cancelled (cancellable) && !local_error) {
GList *link;
+ if (!last_sync_tag) {
+ GSList *uids = NULL, *slink;
+
+ if (e_cache_get_uids (E_CACHE (book_cache), E_CACHE_EXCLUDE_DELETED, &uids, NULL,
cancellable, NULL)) {
+ known_uids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ for (slink = uids; slink; slink = g_slist_next (slink)) {
+ gchar *uid = slink->data;
+
+ if (uid) {
+ g_hash_table_insert (known_uids, uid, NULL);
+ /* Steal the data */
+ slink->data = NULL;
+ }
+ }
+
+ g_slist_free_full (uids, g_free);
+ }
+ }
+
if (gdata_feed_get_updated (feed) > updated_time)
updated_time = gdata_feed_get_updated (feed);
@@ -507,12 +535,15 @@ ebb_google_get_changes_sync (EBookMetaBackend *meta_backend,
if (!GDATA_IS_CONTACTS_CONTACT (gdata_contact))
continue;
- uid = g_strdup (gdata_entry_get_id (GDATA_ENTRY (gdata_contact)));
+ uid = g_strdup (e_book_google_utils_uid_from_entry (GDATA_ENTRY (gdata_contact)));
if (!uid || !*uid) {
g_free (uid);
continue;
}
+ if (known_uids)
+ g_hash_table_remove (known_uids, uid);
+
if (!e_book_cache_get_contact (book_cache, uid, FALSE, &cached_contact, cancellable,
NULL))
cached_contact = NULL;
@@ -634,8 +665,29 @@ ebb_google_get_changes_sync (EBookMetaBackend *meta_backend,
last_updated.tv_usec = 0;
*out_new_sync_tag = g_time_val_to_iso8601 (&last_updated);
+
+ if (!last_sync_tag)
+ e_cache_set_key_int (E_CACHE (book_cache), "google-data-version",
EBB_GOOGLE_DATA_VERSION, NULL);
+
+ if (known_uids) {
+ GHashTableIter iter;
+ gpointer key;
+
+ g_hash_table_iter_init (&iter, known_uids);
+ while (g_hash_table_iter_next (&iter, &key, NULL)) {
+ const gchar *uid = key;
+
+ if (uid) {
+ *out_removed_objects = g_slist_prepend (*out_removed_objects,
+ e_book_meta_backend_info_new (uid, NULL, NULL, NULL));
+ }
+ }
+ }
}
+ if (known_uids)
+ g_hash_table_destroy (known_uids);
+
g_clear_object (&book_cache);
if (local_error) {
diff --git a/src/addressbook/backends/google/e-book-google-utils.c
b/src/addressbook/backends/google/e-book-google-utils.c
index 027eb25a8..098a85c77 100644
--- a/src/addressbook/backends/google/e-book-google-utils.c
+++ b/src/addressbook/backends/google/e-book-google-utils.c
@@ -593,7 +593,7 @@ e_contact_new_from_gdata_entry (GDataEntry *entry,
g_return_val_if_fail (system_groups_by_entry_id != NULL, NULL);
g_return_val_if_fail (g_hash_table_size (system_groups_by_entry_id) > 0, FALSE);
- uid = gdata_entry_get_id (entry);
+ uid = e_book_google_utils_uid_from_entry (entry);
if (NULL == uid)
return NULL;
@@ -1716,3 +1716,21 @@ e_contact_sanitise_google_group_name (GDataEntry *group)
return g_strdup (gdata_entry_get_title (group));
}
}
+
+/* Makes a non-URL UID from a URL ID; the returned string is owned by @entry */
+const gchar *
+e_book_google_utils_uid_from_entry (GDataEntry *entry)
+{
+ const gchar *id, *slash;
+
+ id = gdata_entry_get_id (entry);
+ if (!id)
+ return NULL;
+
+ slash = strrchr (id, '/');
+
+ if (slash && slash[1])
+ return slash + 1;
+
+ return id;
+}
diff --git a/src/addressbook/backends/google/e-book-google-utils.h
b/src/addressbook/backends/google/e-book-google-utils.h
index 6d7e1333d..29e005d97 100644
--- a/src/addressbook/backends/google/e-book-google-utils.h
+++ b/src/addressbook/backends/google/e-book-google-utils.h
@@ -60,6 +60,8 @@ const gchar *e_contact_map_google_with_evo_group (const gchar *group_name, gbool
gchar *e_contact_sanitise_google_group_id (const gchar *group_id) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
gchar *e_contact_sanitise_google_group_name (GDataEntry *group) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+const gchar * e_book_google_utils_uid_from_entry (GDataEntry *entry);
+
G_END_DECLS
#endif /* E_BOOK_GOOGLE_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]