From 9ab5e52c8d0e66e3d13d604604b5c699560abbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Simon=20Fauteux-Chapleau?= <francois-simon.fauteux-chapleau@savoirfairelinux.com> Date: Thu, 14 Nov 2024 17:58:23 -0500 Subject: [PATCH] contactmodel: look up name at most once per peer The ContactModel::bestNameForContact function currently performs a lookup on the name server every time it is called if its argument is the URI of a peer which isn't a contact and doesn't have a registered name. This patch modifies the function's behavior so that it doesn't perform more than one lookup per peer, thus preventing the server from getting spammed with large numbers of unnecessary requests. GitLab: #1882 Change-Id: I7b7ef6a41d3db1001fc1418f8f35bd06b0932624 --- src/libclient/contactmodel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libclient/contactmodel.cpp b/src/libclient/contactmodel.cpp index 72fe3efa1..cd800cbfa 100644 --- a/src/libclient/contactmodel.cpp +++ b/src/libclient/contactmodel.cpp @@ -571,6 +571,16 @@ ContactModel::bestNameForContact(const QString& contactUri) const return *itContact; } else { // This is not a contact, but we should get the registered name + // + // NOTE: bestNameForContact is used by ConversationListModelBase::dataForItem, + // which means that it sometimes gets called multiple times within a short amount + // of time (less than a second), and can easily get called dozens or even hundreds + // of times in total after using Jami for a couple of hours. We don't want to send + // this many requests to the name server, so we store the peer's URI in nonContactLookup_. + // If the call to lookupAddress below succeeds, then the URI will be replaced by the + // peer's registered name, but in any case, this ensures that we don't do more than one + // lookup for a given peer, regardless of how many times bestNameForContact is called. + pimpl_->nonContactLookup_[contactUri] = contactUri; ConfigurationManager::instance().lookupAddress(owner.id, "", contactUri); } } -- GitLab