aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-06-19 15:59:50 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-06-19 15:59:50 +0200
commitf6ad01c959e19362a0b15779b816432595153d3b (patch)
tree1e00da865386f580ce1755a9773110aedd29744b
parente17764a1ae81393968dfb747c7b67353c109bc71 (diff)
downloadlibquotient-f6ad01c959e19362a0b15779b816432595153d3b.tar.gz
libquotient-f6ad01c959e19362a0b15779b816432595153d3b.zip
Revert adding a pause between syncs, use sane timeout defaults
This reverts commit b1071cf34b86685c3cdb5004d6112881966a7ce6. Passing -1 to sync() and, respectively, to SyncJob does not add any timeout; however, careful reading of the spec reveals that the default value for the timeout (0) means to return as soon as possible, not as late as possible. As a consequence, syncLoop() without parameters initiates a sync polling frenzy, with the client sending a new request as soon as the previous returns, while the server returns the request as soon as it practically can, not as soon as another event for the client comes around. To fix this, the default value for syncLoop() is changed to 30 seconds. The recently added msecBetween parameter is abolished; we really don't want to steer people to classic polling from long polling.
-rw-r--r--lib/connection.cpp13
-rw-r--r--lib/connection.h2
2 files changed, 6 insertions, 9 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 0fb301d1..b702c1f9 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -57,7 +57,6 @@
#include <QtCore/QElapsedTimer>
#include <QtCore/QFile>
#include <QtCore/QMimeDatabase>
-#include <QtCore/QTimer>
#include <QtCore/QRegularExpression>
#include <QtCore/QStandardPaths>
#include <QtCore/QStringBuilder>
@@ -518,23 +517,21 @@ void Connection::sync(int timeout)
});
}
-void Connection::syncLoop(int timeout, int msecBetween)
+void Connection::syncLoop(int timeout)
{
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); // swap() is for the nice log below
+ std::swap(d->syncTimeout, timeout);
if (d->syncLoopConnection) {
qCInfo(MAIN) << "Timeout for next syncs changed from"
<< timeout << "to" << d->syncTimeout;
} else {
- d->syncLoopConnection =
- connect(this, &Connection::syncDone, this, [this, msecBetween] {
- QTimer::singleShot(msecBetween, this,
- &Connection::syncLoopIteration);
- });
+ d->syncLoopConnection = connect(this, &Connection::syncDone,
+ this, &Connection::syncLoopIteration,
+ Qt::QueuedConnection);
syncLoopIteration(); // initial sync to start the loop
}
}
diff --git a/lib/connection.h b/lib/connection.h
index 47d1844e..48ea4f5e 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -537,7 +537,7 @@ public slots:
void logout();
void sync(int timeout = -1);
- void syncLoop(int timeout = -1, int msecBetween = 500);
+ void syncLoop(int timeout = 30000);
void stopSync();
QString nextBatchToken() const;