Skip to content
Snippets Groups Projects
Commit 815d3241 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

contactmodel: move profile creation on dedicated thread

This avoid a heavy I/O operation on the main pool

Change-Id: Ic5068d9d1c291b8f27ffc563933d4920af42e890
GitLab: #1450
parent 2343f34b
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "api/contactmodel.h" #include "api/contactmodel.h"
#include <QThreadPool>
// LRC // LRC
#include "api/account.h" #include "api/account.h"
#include "api/contact.h" #include "api/contact.h"
...@@ -121,6 +123,8 @@ public: ...@@ -121,6 +123,8 @@ public:
QString searchStatus_ {}; QString searchStatus_ {};
QMap<QString, QString> nonContactLookup_; QMap<QString, QString> nonContactLookup_;
QThreadPool profileThreadPool;
public Q_SLOTS: public Q_SLOTS:
/** /**
* Listen CallbacksHandler when a presence update occurs * Listen CallbacksHandler when a presence update occurs
...@@ -690,6 +694,7 @@ ContactModelPimpl::~ContactModelPimpl() ...@@ -690,6 +694,7 @@ ContactModelPimpl::~ContactModelPimpl()
&ConfigurationManagerInterface::userSearchEnded, &ConfigurationManagerInterface::userSearchEnded,
this, this,
&ContactModelPimpl::slotUserSearchEnded); &ContactModelPimpl::slotUserSearchEnded);
profileThreadPool.waitForDone();
} }
bool bool
...@@ -1196,44 +1201,46 @@ ContactModelPimpl::slotProfileReceived(const QString& accountId, ...@@ -1196,44 +1201,46 @@ ContactModelPimpl::slotProfileReceived(const QString& accountId,
if (accountId != linked.owner.id) if (accountId != linked.owner.id)
return; return;
QFile vCardFile(path); profileThreadPool.start([=] {
if (!vCardFile.open(QIODevice::ReadOnly | QIODevice::Text)) QFile vCardFile(path);
return; if (!vCardFile.open(QIODevice::ReadOnly | QIODevice::Text))
QTextStream in(&vCardFile); return;
QTextStream in(&vCardFile);
auto vCard = in.readAll();
auto vCard = in.readAll();
profile::Info profileInfo;
profileInfo.uri = peer; profile::Info profileInfo;
profileInfo.type = profile::Type::JAMI; profileInfo.uri = peer;
profileInfo.type = profile::Type::JAMI;
for (auto& e : QString(vCard).split("\n")) {
if (e.contains("PHOTO")) { for (auto& e : QString(vCard).split("\n")) {
auto splitted = e.split(":"); if (e.contains("PHOTO")) {
if (splitted.size() > 1) auto splitted = e.split(":");
profileInfo.avatar = e.split(":")[1]; if (splitted.size() > 1)
} else if (e.contains("FN")) { profileInfo.avatar = e.split(":")[1];
auto splitted = e.split(":"); } else if (e.contains("FN")) {
if (splitted.size() > 1) auto splitted = e.split(":");
profileInfo.alias = e.split(":")[1]; if (splitted.size() > 1)
profileInfo.alias = e.split(":")[1];
}
} }
}
if (peer == linked.owner.profileInfo.uri) { if (peer == linked.owner.profileInfo.uri) {
if (profileInfo.avatar.isEmpty()) if (profileInfo.avatar.isEmpty())
return; // In this case, probably a new device without avatar. return; // In this case, probably a new device without avatar.
// Profile is saved by daemon, just update client // Profile is saved by daemon, just update client
linked.owner.accountModel->setAlias(linked.owner.id, profileInfo.alias, false); linked.owner.accountModel->setAlias(linked.owner.id, profileInfo.alias, false);
linked.owner.accountModel->setAvatar(linked.owner.id, profileInfo.avatar, false); linked.owner.accountModel->setAvatar(linked.owner.id, profileInfo.avatar, false);
return; return;
} }
vCardFile.remove(); vCardFile.remove();
contact::Info contactInfo; contact::Info contactInfo;
contactInfo.profileInfo = profileInfo; contactInfo.profileInfo = profileInfo;
linked.owner.contactModel->addContact(contactInfo); linked.owner.contactModel->addContact(contactInfo);
contactInfo.profileInfo.avatar.clear(); // Do not store after update contactInfo.profileInfo.avatar.clear(); // Do not store after update
});
} }
void void
......
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