Skip to content
Snippets Groups Projects
Commit 9ab5e52c authored by François-Simon Fauteux-Chapleau's avatar François-Simon Fauteux-Chapleau
Browse files

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
parent 56401d41
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment