From a1f7c71feb6a79dae75ce76a28f415cb8c12dbf5 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Mon, 28 Mar 2022 04:27:06 -0700 Subject: [PATCH] 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. --- src/persistence/settings.cpp | 8 ++++---- src/persistence/settings.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index f514d4d47..55fe614a9 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -75,6 +75,7 @@ Settings::Settings(IMessageBoxManager& messageBoxManager_) settingsThread = new QThread(); settingsThread->setObjectName("qTox Settings"); settingsThread->start(QThread::LowPriority); + qRegisterMetaType("const ToxEncrypt*"); moveToThread(settingsThread); loadGlobal(); } @@ -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) diff --git a/src/persistence/settings.h b/src/persistence/settings.h index a9545413b..54363ee4b 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -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: private: struct friendProp; - void savePersonal(QString profileName, const ToxEncrypt* passkey); friendProp& getOrInsertFriendPropRef(const ToxPk& id); static ICoreSettings::ProxyType fixInvalidProxyType(ICoreSettings::ProxyType proxyType); template bool setVal(T& savedVal, T newVal); -public slots: - void savePersonal(Profile* profile); +private slots: + void savePersonal(QString profileName, const ToxEncrypt* passkey); private: bool loaded;