mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Use time the request was send,..
not when it was processed by the client, to determine the quality of the connection.
This commit is contained in:
parent
6818b8e303
commit
9d9eadba8e
12 changed files with 26 additions and 28 deletions
|
@ -53,7 +53,6 @@ AccountState::AccountState(AccountPtr account)
|
|||
this, &AccountState::slotCredentialsFetched);
|
||||
connect(account.data(), &Account::credentialsAsked,
|
||||
this, &AccountState::slotCredentialsAsked);
|
||||
_timeSinceLastETagCheck.invalidate();
|
||||
|
||||
connect(this, &AccountState::isConnectedChanged, [=]{
|
||||
// Get the Apps available on the server if we're now connected.
|
||||
|
@ -181,9 +180,9 @@ bool AccountState::isConnected() const
|
|||
return _state == Connected;
|
||||
}
|
||||
|
||||
void AccountState::tagLastSuccessfullETagRequest()
|
||||
void AccountState::tagLastSuccessfullETagRequest(const QDateTime &tp)
|
||||
{
|
||||
_timeSinceLastETagCheck.start();
|
||||
_timeOfLastETagCheck = tp;
|
||||
}
|
||||
|
||||
QByteArray AccountState::notificationsEtagResponseHeader() const
|
||||
|
@ -227,12 +226,11 @@ void AccountState::checkConnectivity()
|
|||
|
||||
// IF the account is connected the connection check can be skipped
|
||||
// if the last successful etag check job is not so long ago.
|
||||
ConfigFile cfg;
|
||||
std::chrono::milliseconds polltime = cfg.remotePollInterval();
|
||||
|
||||
if (isConnected() && _timeSinceLastETagCheck.isValid()
|
||||
&& !_timeSinceLastETagCheck.hasExpired(polltime.count())) {
|
||||
qCDebug(lcAccountState) << account()->displayName() << "The last ETag check succeeded within the last " << polltime.count() / 1000 << " secs. No connection check needed!";
|
||||
const auto polltime = std::chrono::duration_cast<std::chrono::seconds>(ConfigFile().remotePollInterval());
|
||||
const auto elapsed = _timeOfLastETagCheck.secsTo(QDateTime::currentDateTimeUtc());
|
||||
if (isConnected() && _timeOfLastETagCheck.isValid()
|
||||
&& elapsed <= polltime.count()) {
|
||||
qCDebug(lcAccountState) << account()->displayName() << "The last ETag check succeeded within the last " << polltime.count() << "s (" << elapsed << "s). No connection check needed!";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public:
|
|||
* the server to validate the connection if the last successful etag job
|
||||
* was not so long ago.
|
||||
*/
|
||||
void tagLastSuccessfullETagRequest();
|
||||
void tagLastSuccessfullETagRequest(const QDateTime &tp);
|
||||
|
||||
/** Saves the ETag Response header from the last Notifications api
|
||||
* request with statusCode 200.
|
||||
|
@ -195,7 +195,7 @@ private:
|
|||
ConnectionStatus _connectionStatus;
|
||||
QStringList _connectionErrors;
|
||||
bool _waitingForNewCredentials;
|
||||
QElapsedTimer _timeSinceLastETagCheck;
|
||||
QDateTime _timeOfLastETagCheck;
|
||||
QPointer<ConnectionValidator> _connectionValidator;
|
||||
QByteArray _notificationsEtagResponseHeader;
|
||||
QByteArray _navigationAppsEtagResponseHeader;
|
||||
|
|
|
@ -343,7 +343,7 @@ void Folder::slotRunEtagJob()
|
|||
// The _requestEtagJob is auto deleting itself on finish. Our guard pointer _requestEtagJob will then be null.
|
||||
}
|
||||
|
||||
void Folder::etagRetrieved(const QString &etag)
|
||||
void Folder::etagRetrieved(const QString &etag, const QDateTime &tp)
|
||||
{
|
||||
// re-enable sync if it was disabled because network was down
|
||||
FolderMan::instance()->setSyncEnabled(true);
|
||||
|
@ -354,13 +354,13 @@ void Folder::etagRetrieved(const QString &etag)
|
|||
slotScheduleThisFolder();
|
||||
}
|
||||
|
||||
_accountState->tagLastSuccessfullETagRequest();
|
||||
_accountState->tagLastSuccessfullETagRequest(tp);
|
||||
}
|
||||
|
||||
void Folder::etagRetrievedFromSyncEngine(const QString &etag)
|
||||
void Folder::etagRetrievedFromSyncEngine(const QString &etag, const QDateTime &time)
|
||||
{
|
||||
qCInfo(lcFolder) << "Root etag from during sync:" << etag;
|
||||
accountState()->tagLastSuccessfullETagRequest();
|
||||
accountState()->tagLastSuccessfullETagRequest(time);
|
||||
_lastEtag = etag;
|
||||
}
|
||||
|
||||
|
|
|
@ -372,8 +372,8 @@ private slots:
|
|||
void slotItemCompleted(const SyncFileItemPtr &);
|
||||
|
||||
void slotRunEtagJob();
|
||||
void etagRetrieved(const QString &);
|
||||
void etagRetrievedFromSyncEngine(const QString &);
|
||||
void etagRetrieved(const QString &, const QDateTime &tp);
|
||||
void etagRetrievedFromSyncEngine(const QString &, const QDateTime &time);
|
||||
|
||||
void slotEmitFinishedDelayed();
|
||||
|
||||
|
|
|
@ -282,6 +282,7 @@ void AbstractNetworkJob::slotFinished()
|
|||
|
||||
QByteArray AbstractNetworkJob::responseTimestamp()
|
||||
{
|
||||
ASSERT(!_responseTimestamp.isEmpty());
|
||||
return _responseTimestamp;
|
||||
}
|
||||
|
||||
|
|
|
@ -277,6 +277,6 @@ private:
|
|||
signals:
|
||||
void finished();
|
||||
// The root etag of this directory was fetched
|
||||
void etag(const QString &);
|
||||
void etag(const QString &, const QDateTime &time);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -499,10 +499,11 @@ void DiscoverySingleDirectoryJob::lsJobFinishedWithoutErrorSlot()
|
|||
deleteLater();
|
||||
return;
|
||||
} else if (_isE2eEncrypted) {
|
||||
emit etag(_firstEtag, QDateTime::fromString(QString::fromUtf8(_lsColJob->responseTimestamp()), Qt::RFC2822Date));
|
||||
fetchE2eMetadata();
|
||||
return;
|
||||
}
|
||||
emit etag(_firstEtag);
|
||||
emit etag(_firstEtag, QDateTime::fromString(QString::fromUtf8(_lsColJob->responseTimestamp()), Qt::RFC2822Date));
|
||||
emit finished(_results);
|
||||
deleteLater();
|
||||
}
|
||||
|
@ -561,7 +562,6 @@ void DiscoverySingleDirectoryJob::metadataReceived(const QJsonDocument &json, in
|
|||
return result;
|
||||
});
|
||||
|
||||
emit etag(_firstEtag);
|
||||
emit finished(_results);
|
||||
deleteLater();
|
||||
}
|
||||
|
@ -569,7 +569,6 @@ void DiscoverySingleDirectoryJob::metadataReceived(const QJsonDocument &json, in
|
|||
void DiscoverySingleDirectoryJob::metadataError(const QByteArray &fileId, int httpReturnCode)
|
||||
{
|
||||
qCWarning(lcDiscovery) << "E2EE Metadata job error. Trying to proceed without it." << fileId << httpReturnCode;
|
||||
emit etag(_firstEtag);
|
||||
emit finished(_results);
|
||||
deleteLater();
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ public:
|
|||
// This is not actually a network job, it is just a job
|
||||
signals:
|
||||
void firstDirectoryPermissions(RemotePermissions);
|
||||
void etag(const QString &);
|
||||
void etag(const QString &, const QDateTime &time);
|
||||
void finished(const HttpResult<QVector<RemoteInfo>> &result);
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -129,7 +129,7 @@ bool RequestEtagJob::finished()
|
|||
}
|
||||
}
|
||||
}
|
||||
emit etagRetrieved(etag);
|
||||
emit etagRetrieved(etag, QDateTime::fromString(QString::fromUtf8(_responseTimestamp), Qt::RFC2822Date));
|
||||
emit finishedWithResult(etag);
|
||||
} else {
|
||||
emit finishedWithResult(HttpError{ httpCode, errorString() });
|
||||
|
|
|
@ -348,7 +348,7 @@ public:
|
|||
void start() override;
|
||||
|
||||
signals:
|
||||
void etagRetrieved(const QString &etag);
|
||||
void etagRetrieved(const QString &etag, const QDateTime &time);
|
||||
void finishedWithResult(const HttpResult<QString> &etag);
|
||||
|
||||
private slots:
|
||||
|
|
|
@ -607,12 +607,12 @@ void SyncEngine::slotFolderDiscovered(bool local, const QString &folder)
|
|||
emit transmissionProgress(*_progressInfo);
|
||||
}
|
||||
|
||||
void SyncEngine::slotRootEtagReceived(const QString &e)
|
||||
void SyncEngine::slotRootEtagReceived(const QString &e, const QDateTime &time)
|
||||
{
|
||||
if (_remoteRootEtag.isEmpty()) {
|
||||
qCDebug(lcEngine) << "Root etag:" << e;
|
||||
_remoteRootEtag = e;
|
||||
emit rootEtag(_remoteRootEtag);
|
||||
emit rootEtag(_remoteRootEtag, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ public:
|
|||
|
||||
signals:
|
||||
// During update, before reconcile
|
||||
void rootEtag(QString);
|
||||
void rootEtag(const QString &, const QDateTime &);
|
||||
|
||||
// after the above signals. with the items that actually need propagating
|
||||
void aboutToPropagate(SyncFileItemVector &);
|
||||
|
@ -172,7 +172,7 @@ signals:
|
|||
|
||||
private slots:
|
||||
void slotFolderDiscovered(bool local, const QString &folder);
|
||||
void slotRootEtagReceived(const QString &);
|
||||
void slotRootEtagReceived(const QString &, const QDateTime &time);
|
||||
|
||||
/** When the discovery phase discovers an item */
|
||||
void slotItemDiscovered(const SyncFileItemPtr &item);
|
||||
|
|
Loading…
Reference in a new issue