aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Andreyev <aa13q@ya.ru>2019-02-04 11:58:43 +0300
committerAlexey Andreyev <aa13q@ya.ru>2019-02-05 13:59:49 +0300
commitbf6cd3d29052f9e79fee29c6a6646d95271a196a (patch)
treea2cfed8c2815fd1a2098effc2ea64847324e49b9
parent22dd5f1e8988b03a691487cdad164a82a36e7f8c (diff)
downloadlibquotient-bf6cd3d29052f9e79fee29c6a6646d95271a196a.tar.gz
libquotient-bf6cd3d29052f9e79fee29c6a6646d95271a196a.zip
Connection: simplified sync loop logic without delays
Signed-off-by: Alexey Andreyev <aa13q@ya.ru>
-rw-r--r--lib/connection.cpp58
-rw-r--r--lib/connection.h26
2 files changed, 4 insertions, 80 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index e7f9e4b2..a9a8bba3 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -45,7 +45,6 @@
#include <QtCore/QRegularExpression>
#include <QtCore/QMimeDatabase>
#include <QtCore/QCoreApplication>
-#include <QTimer>
using namespace QMatrixClient;
@@ -256,6 +255,7 @@ void Connection::Private::connectWithToken(const QString& user,
<< "by user" << userId << "from device" << deviceId;
emit q->stateChanged();
emit q->connected();
+
}
void Connection::checkAndConnect(const QString& userId,
@@ -327,10 +327,8 @@ void Connection::sync(int timeout)
void Connection::syncLoop(int timeout)
{
_syncLoopTimeout = timeout;
- connect(this, &Connection::syncDone, this, &Connection::getNewEventsOnSyncDone);
- connect(this, &Connection::syncError, this, &Connection::getNewEventsOnSyncError);
- _syncLoopElapsedTimer.start();
- sync(_syncLoopTimeout); // initial sync to start the loop
+ connect(this, &Connection::syncDone, this, &Connection::syncLoopIteration);
+ syncLoopIteration(); // initial sync to start the loop
}
void Connection::onSyncSuccess(SyncData &&data, bool fromCache) {
@@ -420,37 +418,6 @@ void Connection::onSyncSuccess(SyncData &&data, bool fromCache) {
}
}
-void Connection::getNewEvents()
-{
- int delay = minSyncLoopDelayMs() - _syncLoopElapsedTimer.restart();
- if (delay<0) {
- delay = 0;
- }
- QTimer::singleShot(delay, this, &Connection::syncLoopIteration);
-}
-
-void Connection::getNewEventsOnSyncDone()
-{
- if (_prevSyncLoopIterationDone) {
- _syncLoopAttemptNumber++;
- } else {
- _syncLoopAttemptNumber = 0;
- }
- emit syncAttemptNumberChanged(_syncLoopAttemptNumber);
- getNewEvents();
-}
-
-void Connection::getNewEventsOnSyncError()
-{
- if (_prevSyncLoopIterationDone) {
- _syncLoopAttemptNumber = 0;
- } else {
- _syncLoopAttemptNumber++;
- }
- emit syncAttemptNumberChanged(_syncLoopAttemptNumber);
- getNewEvents();
-}
-
void Connection::stopSync()
{
if (d->syncJob)
@@ -470,15 +437,6 @@ PostReceiptJob* Connection::postReceipt(Room* room, RoomEvent* event) const
return callApi<PostReceiptJob>(room->id(), "m.read", event->id());
}
-void Connection::setMinSyncDelayMs(qint64 minSyncDelayMs)
-{
- if (_minSyncLoopDelayMs == minSyncDelayMs)
- return;
-
- _minSyncLoopDelayMs = minSyncDelayMs;
- emit minSyncDelayMsChanged(_minSyncLoopDelayMs);
-}
-
JoinRoomJob* Connection::joinRoom(const QString& roomAlias,
const QStringList& serverNames)
{
@@ -1143,16 +1101,6 @@ user_factory_t Connection::userFactory()
return _userFactory;
}
-qint64 Connection::minSyncLoopDelayMs() const
-{
- return _minSyncLoopDelayMs;
-}
-
-uint Connection::syncLoopAttemptNumber() const
-{
- return _syncLoopAttemptNumber;
-}
-
room_factory_t Connection::_roomFactory = defaultRoomFactory<>();
user_factory_t Connection::_userFactory = defaultUserFactory<>();
diff --git a/lib/connection.h b/lib/connection.h
index ee7ad243..c9ca3580 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -26,7 +26,6 @@
#include <QtCore/QObject>
#include <QtCore/QUrl>
#include <QtCore/QSize>
-#include <QElapsedTimer>
#include <functional>
#include <memory>
@@ -106,8 +105,6 @@ namespace QMatrixClient
Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver NOTIFY homeserverChanged)
Q_PROPERTY(bool cacheState READ cacheState WRITE setCacheState NOTIFY cacheStateChanged)
Q_PROPERTY(bool lazyLoading READ lazyLoading WRITE setLazyLoading NOTIFY lazyLoadingChanged)
- Q_PROPERTY(qint64 minSyncLoopDelayMs READ minSyncLoopDelayMs WRITE setMinSyncDelayMs NOTIFY minSyncDelayMsChanged)
- Q_PROPERTY(uint syncLoopAttemptNumber READ syncLoopAttemptNumber NOTIFY syncAttemptNumberChanged)
public:
// Room ids, rather than room pointers, are used in the direct chat
@@ -356,11 +353,6 @@ namespace QMatrixClient
template <typename T>
static void setUserType() { setUserFactory(defaultUserFactory<T>()); }
- qint64 minSyncLoopDelayMs() const;
- void setMinSyncDelayMs(qint64 minSyncLoopDelayMs);
-
- uint syncLoopAttemptNumber() const;
-
public slots:
/** Set the homeserver base URL */
void setHomeserver(const QUrl& baseUrl);
@@ -379,13 +371,6 @@ namespace QMatrixClient
void logout();
void sync(int timeout = -1);
-
- /** Start sync loop with the minSyncLoopDelayMs value
- where minSyncLoopDelayMs could be changed on the client
- according to syncDone/syncError signals and
- the syncLoopAttemptNumber counter.
- The syncLoopAttemptNumber counter is resetting
- after non-repeating syncDone/syncError events*/
void syncLoop(int timeout = -1);
void stopSync();
@@ -662,8 +647,6 @@ namespace QMatrixClient
void cacheStateChanged();
void lazyLoadingChanged();
void turnServersChanged(const QJsonObject& servers);
- void minSyncDelayMsChanged(qint64 minSyncLoopDelayMs);
- void syncAttemptNumberChanged(uint syncLoopAttemptNumber);
protected:
/**
@@ -699,9 +682,7 @@ namespace QMatrixClient
void onSyncSuccess(SyncData &&data, bool fromCache = false);
protected slots:
- void getNewEvents();
- void getNewEventsOnSyncDone();
- void getNewEventsOnSyncError();
+ void syncLoopIteration();
private:
class Private;
@@ -727,12 +708,7 @@ namespace QMatrixClient
static room_factory_t _roomFactory;
static user_factory_t _userFactory;
- QElapsedTimer _syncLoopElapsedTimer;
int _syncLoopTimeout = -1;
- qint64 _minSyncLoopDelayMs = 0;
- void syncLoopIteration();
- uint _syncLoopAttemptNumber = 0;
- bool _prevSyncLoopIterationDone = false;
};
} // namespace QMatrixClient
Q_DECLARE_METATYPE(QMatrixClient::Connection*)