[telepathy-glib/master] tp_connection_get_contacts_by_handle(): avoid DBus calls when possible.
David Laban
david.laban at collabora.co.uk
Fri Nov 20 09:37:19 PST 2009
Fixes b.fd.o #25181.
If we already have all TpContact objects, we don't need to HoldHandles()
or GetContactAttributes()
---
telepathy-glib/contact.c | 64 ++++++++++++++++++++++++++++++++++++++++------
1 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/telepathy-glib/contact.c b/telepathy-glib/contact.c
index c9a0cac..846d9b2 100644
--- a/telepathy-glib/contact.c
+++ b/telepathy-glib/contact.c
@@ -989,6 +989,12 @@ contacts_context_continue (ContactsContext *c)
}
}
+static gboolean
+contacts_context_idle_continue (gpointer data)
+{
+ contacts_context_continue (data);
+ return FALSE;
+}
static void
contacts_held_one (TpConnection *connection,
@@ -1839,6 +1845,34 @@ contacts_get_attributes (ContactsContext *context)
g_free (supported_interfaces);
}
+/*
+ * Returns a new GPtrArray of borrowed references to TpContacts,
+ * or NULL if any contacts could not be found.
+ */
+static GPtrArray *
+lookup_all_contacts (ContactsContext *context)
+{
+ GPtrArray *contacts = g_ptr_array_new ();
+ guint i;
+
+ for (i = 0; i < context->handles->len; i++)
+ {
+ TpContact *contact = _tp_connection_lookup_contact (context->connection,
+ g_array_index (context->handles, TpHandle, i));
+ if (contact != NULL)
+ {
+ g_ptr_array_add (contacts, contact);
+ }
+ else
+ {
+ g_ptr_array_free (contacts, TRUE);
+ contacts = NULL;
+ break;
+ }
+ }
+
+ return contacts;
+}
/**
* tp_connection_get_contacts_by_handle:
@@ -1881,6 +1915,7 @@ tp_connection_get_contacts_by_handle (TpConnection *self,
{
ContactFeatureFlags feature_flags = 0;
ContactsContext *context;
+ GPtrArray *contacts;
guint i;
g_return_if_fail (tp_connection_is_ready (self));
@@ -1902,6 +1937,27 @@ tp_connection_get_contacts_by_handle (TpConnection *self,
g_array_append_vals (context->handles, handles, n_handles);
+ contacts = lookup_all_contacts (context);
+
+ if (contacts != NULL)
+ {
+ /* We have already held/inspected handles, so we can skip that. */
+ for (i = 0; i < n_handles; i++)
+ {
+ TpContact *contact = g_object_ref (g_ptr_array_index (contacts, i));
+
+ g_ptr_array_add (context->contacts, contact);
+ }
+
+ contacts_context_queue_features (context, feature_flags);
+
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ contacts_context_idle_continue, context, contacts_context_unref);
+
+ g_ptr_array_free (contacts, TRUE);
+ return;
+ }
+
if (tp_proxy_has_interface_by_id (self,
TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACTS))
{
@@ -1932,14 +1988,6 @@ tp_connection_get_contacts_by_handle (TpConnection *self,
}
-static gboolean
-contacts_context_idle_continue (gpointer data)
-{
- contacts_context_continue (data);
- return FALSE;
-}
-
-
/**
* tp_connection_upgrade_contacts:
* @self: A connection, which must be ready (#TpConnection:connection-ready
--
1.5.6.5
More information about the telepathy-commits
mailing list