From 44c81db3cf13bc8916320d0907f0043e78be9e38 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Tue, 20 Aug 2013 22:54:07 +0300 Subject: [PATCH] ucs: optimize contact list update requests The server sends us a NOTIFY with an update contact list after we have made changes to UCS. Instead of generating a useless GetImListItems operation we now ignore those update triggers that arrive within 10 seconds of our last response. Not perfect, but this reduces the network traffic considerably when the user is making many changes to the buddy list in a short time. --- src/core/sipe-ucs.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/core/sipe-ucs.c b/src/core/sipe-ucs.c index b044d9d2..9a907ed3 100644 --- a/src/core/sipe-ucs.c +++ b/src/core/sipe-ucs.c @@ -28,6 +28,7 @@ #include #include +#include #include "sipe-backend.h" #include "sipe-buddy.h" @@ -63,6 +64,7 @@ struct sipe_ucs { gchar *ews_url; GSList *deferred_requests; GSList *pending_requests; + time_t last_response; guint group_id; gboolean migrated; gboolean shutting_down; @@ -247,11 +249,12 @@ void sipe_ucs_get_photo(struct sipe_core_private *sipe_private, g_free(body); } -static void sipe_ucs_ignore_response(SIPE_UNUSED_PARAMETER struct sipe_core_private *sipe_private, +static void sipe_ucs_ignore_response(struct sipe_core_private *sipe_private, SIPE_UNUSED_PARAMETER const sipe_xml *body, SIPE_UNUSED_PARAMETER gpointer callback_data) { SIPE_DEBUG_INFO_NOFORMAT("sipe_ucs_ignore_response: done"); + sipe_private->ucs->last_response = time(NULL); } static void ucs_extract_keys(const sipe_xml *persona_node, @@ -289,6 +292,8 @@ static void sipe_ucs_add_new_im_contact_to_group_response(struct sipe_core_priva const sipe_xml *persona_node = sipe_xml_child(body, "AddNewImContactToGroupResponse/Persona"); + sipe_private->ucs->last_response = time(NULL); + if (persona_node && buddy && is_empty(buddy->exchange_key) && @@ -412,6 +417,8 @@ static void sipe_ucs_add_im_group_response(struct sipe_core_private *sipe_privat "AddImGroupResponse/ImGroup"); struct sipe_group *group = ucs_create_group(sipe_private, group_node); + sipe_private->ucs->last_response = time(NULL); + if (group) { struct sipe_buddy *buddy = sipe_buddy_find_by_uri(sipe_private, who); @@ -624,10 +631,23 @@ void sipe_ucs_init(struct sipe_core_private *sipe_private, struct sipe_ucs *ucs; if (sipe_private->ucs) { - /* contact list update trigger -> request list again */ - if (SIPE_CORE_PRIVATE_FLAG_IS(SUBSCRIBED_BUDDIES)) - ucs_get_im_item_list(sipe_private); + struct sipe_ucs *ucs = sipe_private->ucs; + + /* + * contact list update trigger -> request list again + * + * If the trigger arrives less than 10 seconds after our + * last UCS response, then ignore it, because it is caused + * by our own changes to the contact list. + */ + if (SIPE_CORE_PRIVATE_FLAG_IS(SUBSCRIBED_BUDDIES)) { + if ((time(NULL) - ucs->last_response) >= 10) + ucs_get_im_item_list(sipe_private); + else + SIPE_DEBUG_INFO_NOFORMAT("sipe_ucs_init: ignoring this contact list update - triggered by our last change"); + } + ucs->last_response = 0; return; } -- 2.11.4.GIT