Browse Source

perf(Settings): Make personal settings saving consistently async

The function is documented as async, but is only async when called from
a different thread. Save is called from within Settings, it looks like
only from public functions that would be called on other threads, but
make it async regardless of calling thread for consistency.

There is already a sync function that is used, so safety is not lost.
reviewable/pr6596/r1
Anthony Bilinski 3 years ago
parent
commit
a1f7c71feb
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 8
      src/persistence/settings.cpp
  2. 6
      src/persistence/settings.h

8
src/persistence/settings.cpp

@ -75,6 +75,7 @@ Settings::Settings(IMessageBoxManager& messageBoxManager_) @@ -75,6 +75,7 @@ Settings::Settings(IMessageBoxManager& messageBoxManager_)
settingsThread = new QThread();
settingsThread->setObjectName("qTox Settings");
settingsThread->start(QThread::LowPriority);
qRegisterMetaType<const ToxEncrypt*>("const ToxEncrypt*");
moveToThread(settingsThread);
loadGlobal();
}
@ -762,10 +763,9 @@ void Settings::savePersonal(Profile* profile) @@ -762,10 +763,9 @@ void Settings::savePersonal(Profile* profile)
qDebug() << "Could not save personal settings because there is no active profile";
return;
}
if (QThread::currentThread() != settingsThread)
return (void)QMetaObject::invokeMethod(this, "savePersonal",
Q_ARG(Profile*, profile));
savePersonal(profile->getName(), profile->getPasskey());
QMetaObject::invokeMethod(this, "savePersonal",
Q_ARG(QString, profile->getName()),
Q_ARG(const ToxEncrypt*, profile->getPasskey()));
}
void Settings::savePersonal(QString profileName, const ToxEncrypt* passkey)

6
src/persistence/settings.h

@ -158,6 +158,7 @@ public: @@ -158,6 +158,7 @@ public:
void createPersonal(const QString& basename) const;
void savePersonal();
void savePersonal(Profile* profile);
void loadGlobal();
void loadPersonal(QString profileName, const ToxEncrypt* passKey, bool newProfile);
@ -573,15 +574,14 @@ public: @@ -573,15 +574,14 @@ public:
private:
struct friendProp;
void savePersonal(QString profileName, const ToxEncrypt* passkey);
friendProp& getOrInsertFriendPropRef(const ToxPk& id);
static ICoreSettings::ProxyType fixInvalidProxyType(ICoreSettings::ProxyType proxyType);
template <typename T>
bool setVal(T& savedVal, T newVal);
public slots:
void savePersonal(Profile* profile);
private slots:
void savePersonal(QString profileName, const ToxEncrypt* passkey);
private:
bool loaded;

Loading…
Cancel
Save