telepathy-gabble: Cache PEP aliases in =?UTF-8?Q?=20a=C2=A0hash=20table?=, not deprecated handle qdata
Simon McVittie
smcv at kemper.freedesktop.org
Wed Sep 11 05:01:55 PDT 2013
Module: telepathy-gabble
Branch: master
Commit: 89f9684bdda3fbdc69f19d590786f51544c3b00f
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=89f9684bdda3fbdc69f19d590786f51544c3b00f
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue Sep 10 19:06:27 2013 +0100
Cache PEP aliases in a hash table, not deprecated handle qdata
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69194
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Xavier Claessens <xavier.claessens at collabora.co.uk>
---
src/conn-aliasing.c | 53 ++++++++++++++++++++------------------------------
src/conn-aliasing.h | 1 +
src/connection.c | 1 +
src/connection.h | 6 +++++
4 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 2663703..d7870ee 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -39,16 +39,12 @@
static void gabble_conn_aliasing_pep_nick_reply_handler (
GabbleConnection *conn, WockyStanza *msg, TpHandle handle);
-static GQuark gabble_conn_aliasing_pep_alias_quark (void);
static GabbleConnectionAliasSource _gabble_connection_get_cached_remote_alias (
GabbleConnection *, TpHandle, gchar **);
static void maybe_request_vcard (GabbleConnection *self, TpHandle handle,
GabbleConnectionAliasSource source);
-/* distinct from any strdup()d pointer - used for negative caching */
-static const gchar *NO_ALIAS = "";
-
/**
* gabble_connection_get_alias_flags
*
@@ -202,12 +198,10 @@ static void
_cache_negatively (GabbleConnection *self,
TpHandle handle)
{
- TpBaseConnection *base = (TpBaseConnection *) self;
- TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
- TP_HANDLE_TYPE_CONTACT);
-
- tp_handle_set_qdata (contact_handles, handle,
- gabble_conn_aliasing_pep_alias_quark (), (gchar *) NO_ALIAS, NULL);
+ /* We don't actually need to distinguish between "uncached" and
+ * "known to have no alias" because of how PEP works, so just
+ * remove it from the cache. */
+ g_hash_table_remove (self->pep_alias_cache, GUINT_TO_POINTER (handle));
}
/* Cache pep if successful */
@@ -632,20 +626,6 @@ gabble_connection_set_aliases (TpSvcConnectionInterfaceAliasing *iface,
}
}
-
-GQuark
-gabble_conn_aliasing_pep_alias_quark (void)
-{
- static GQuark quark = 0;
-
- if (G_UNLIKELY (quark == 0))
- quark = g_quark_from_static_string
- ("gabble_conn_aliasing_pep_alias_quark");
-
- return quark;
-}
-
-
static gboolean
_grab_nickname (GabbleConnection *self,
TpHandle handle,
@@ -654,7 +634,6 @@ _grab_nickname (GabbleConnection *self,
TpBaseConnection *base = (TpBaseConnection *) self;
TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
TP_HANDLE_TYPE_CONTACT);
- GQuark quark = gabble_conn_aliasing_pep_alias_quark ();
const gchar *old, *nickname;
node = wocky_node_get_child_ns (node, "nick", NS_NICK);
@@ -668,23 +647,26 @@ _grab_nickname (GabbleConnection *self,
}
nickname = node->content;
- old = tp_handle_get_qdata (contact_handles, handle, quark);
+
+ old = g_hash_table_lookup (self->pep_alias_cache, GUINT_TO_POINTER (handle));
if (tp_strdiff (old, nickname))
{
if (nickname == NULL)
{
- DEBUG ("got empty <nick/> node, caching as NO_ALIAS");
+ DEBUG ("got empty <nick/> node, caching negatively");
_cache_negatively (self, handle);
}
else
{
- tp_handle_set_qdata (contact_handles, handle, quark, g_strdup (nickname),
- g_free);
+ DEBUG ("caching positively");
+ g_hash_table_insert (self->pep_alias_cache, GUINT_TO_POINTER (handle),
+ g_strdup (nickname));
}
gabble_conn_aliasing_nickname_updated ((GObject *) self, handle, self);
}
+
return TRUE;
}
@@ -909,9 +891,9 @@ get_cached_remote_alias (
const gchar *tmp;
gchar *resource;
- tmp = tp_handle_get_qdata (contact_handles, handle,
- gabble_conn_aliasing_pep_alias_quark ());
- if (tmp != NULL && tmp != NO_ALIAS)
+ tmp = g_hash_table_lookup (conn->pep_alias_cache, GUINT_TO_POINTER (handle));
+
+ if (tmp != NULL)
{
maybe_set (alias, tmp);
return GABBLE_CONNECTION_ALIAS_FROM_PRESENCE;
@@ -1183,12 +1165,19 @@ conn_aliasing_init (GabbleConnection *conn)
conn_aliasing_fill_contact_attributes);
conn->pep_nick = wocky_pep_service_new (NS_NICK, TRUE);
+ conn->pep_alias_cache = g_hash_table_new_full (NULL, NULL, NULL, g_free);
g_signal_connect (conn->pep_nick, "changed",
G_CALLBACK (pep_nick_node_changed), conn);
}
void
+conn_aliasing_finalize (GabbleConnection *conn)
+{
+ tp_clear_pointer (&conn->pep_alias_cache, g_hash_table_unref);
+}
+
+void
conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data)
{
TpSvcConnectionInterfaceAliasingClass *klass = g_iface;
diff --git a/src/conn-aliasing.h b/src/conn-aliasing.h
index 353e323..d165449 100644
--- a/src/conn-aliasing.h
+++ b/src/conn-aliasing.h
@@ -28,6 +28,7 @@
G_BEGIN_DECLS
void conn_aliasing_init (GabbleConnection *conn);
+void conn_aliasing_finalize (GabbleConnection *conn);
void conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data);
void gabble_conn_aliasing_nickname_updated (GObject *object,
diff --git a/src/connection.c b/src/connection.c
index 4bc10fc..5556b1e 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1367,6 +1367,7 @@ gabble_connection_finalize (GObject *object)
tp_contacts_mixin_finalize (G_OBJECT(self));
+ conn_aliasing_finalize (self);
conn_presence_finalize (self);
conn_contact_info_finalize (self);
diff --git a/src/connection.h b/src/connection.h
index c3e9138..653ec6a 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -248,6 +248,12 @@ struct _GabbleConnection {
/* ContactInfo.SupportedFields, or NULL to use the generic one */
GPtrArray *contact_info_fields;
+ /* Contacts' aliases from PEP. Private to conn-aliasing.c.
+ * TpHandle => (transfer full) gchar *
+ * We don't distinguish between "not cached" and "known to have
+ * no PEP alias" here. */
+ GHashTable *pep_alias_cache;
+
GabbleConnectionPrivate *priv;
};
More information about the telepathy-commits
mailing list