1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-03-28 14:56:19 +01:00

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
This commit is contained in:
François-Simon Fauteux-Chapleau 2024-11-14 17:58:23 -05:00
parent 56401d4125
commit 9ab5e52c8d

View file

@ -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);
}
}