diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-06-12 20:29:46 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-06-12 20:29:46 +0200 |
commit | b1071cf34b86685c3cdb5004d6112881966a7ce6 (patch) | |
tree | db55bfb3a906ef6152bcfa61aef16a3a09e6e911 /lib/connection.cpp | |
parent | ebdb2ba9d15e6cdfb1458e7895032afd641aafe3 (diff) | |
download | libquotient-b1071cf34b86685c3cdb5004d6112881966a7ce6.tar.gz libquotient-b1071cf34b86685c3cdb5004d6112881966a7ce6.zip |
Connection::syncLoop: give a pause between syncs
As it's observed now, Synapse responds almost immediately on /sync
requests - even if there are no events to return. This downgrades
long-polling to simply polling, and since clients don't expect it,
polling loops become pretty violent. To alleviate that somehow,
syncLoop now accepts the second parameter, msecBetween (500 msecs
by default), to configure waiting between the previous sync response
and the next sync request. This is only for syncLoop();
Connection::sync() fires instantly, as before.
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 50e31d52..d53c308f 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -57,6 +57,7 @@ #include <QtCore/QElapsedTimer> #include <QtCore/QFile> #include <QtCore/QMimeDatabase> +#include <QtCore/QTimer> #include <QtCore/QRegularExpression> #include <QtCore/QStandardPaths> #include <QtCore/QStringBuilder> @@ -506,21 +507,23 @@ void Connection::sync(int timeout) }); } -void Connection::syncLoop(int timeout) +void Connection::syncLoop(int timeout, int msecBetween) { if (d->syncLoopConnection && d->syncTimeout == timeout) { qCInfo(MAIN) << "Attempt to run sync loop but there's one already " "running; nothing will be done"; return; } - std::swap(d->syncTimeout, timeout); + std::swap(d->syncTimeout, timeout); // swap() is for the nice log below if (d->syncLoopConnection) { qCInfo(MAIN) << "Timeout for next syncs changed from" << timeout << "to" << d->syncTimeout; } else { - d->syncLoopConnection = connect(this, &Connection::syncDone, - this, &Connection::syncLoopIteration, - Qt::QueuedConnection); + d->syncLoopConnection = + connect(this, &Connection::syncDone, this, [this, msecBetween] { + QTimer::singleShot(msecBetween, this, + &Connection::syncLoopIteration); + }); syncLoopIteration(); // initial sync to start the loop } } |