Use time the request was send,..
authorHannah von Reth <hannah.vonreth@owncloud.com>
Thu, 3 Dec 2020 15:27:43 +0000 (16:27 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 10:01:08 +0000 (11:01 +0100)
not when it was processed by the client, to determine the quality of the connection.

12 files changed:
src/gui/accountstate.cpp
src/gui/accountstate.h
src/gui/folder.cpp
src/gui/folder.h
src/libsync/abstractnetworkjob.cpp
src/libsync/discovery.h
src/libsync/discoveryphase.cpp
src/libsync/discoveryphase.h
src/libsync/networkjobs.cpp
src/libsync/networkjobs.h
src/libsync/syncengine.cpp
src/libsync/syncengine.h

index 4aace2e9c7c5d2740d5ad7fe657ef3368b8408dc..90c05fefed675b226975cdaf2f68b698a9e63cb7 100644 (file)
@@ -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;
     }
 
index d4b158b653a606ce28c33c2d69524dbfc3d0df4d..4c6bba62d8e7c3959375a8007b221a3210327eca 100644 (file)
@@ -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;
index c542de947de61f426f6c30683d11bce5fc29e975..7aef176969f7bd1eef8a54033e49de6ec159ff22 100644 (file)
@@ -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;
 }
 
index 91e4ce8d45f951390118dbcb4489f421b1f25a4e..5150d3ac04f5182245801d1f406579124d4bc87d 100644 (file)
@@ -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();
 
index 7482d7b462c758ac7b6461116600e5a43d3ebb04..be9c01c9312e951435143d4c9bf55c8dc9049abb 100644 (file)
@@ -282,6 +282,7 @@ void AbstractNetworkJob::slotFinished()
 
 QByteArray AbstractNetworkJob::responseTimestamp()
 {
+    ASSERT(!_responseTimestamp.isEmpty());
     return _responseTimestamp;
 }
 
index a45050827ea89b36678ac393bfa7b7990638d677..2d036b9a9e977c29c9c8868b47a44a15186c17b6 100644 (file)
@@ -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);
 };
 }
index d79497df923965a00f5e04097d13082f6417f993..bbe6280f39bf63fa55bf541f7d5ad6426ed21697 100644 (file)
@@ -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();
 }
index 748d575378b4139fb8d36fa2daa57f074d5b4848..20aab7311a122bb023ab5b68bbbb91959df4f76e 100644 (file)
@@ -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:
index ee47446a25fad360c57bc1d9084e57251cec5412..d70d28a4442aee039c762b1b8c423d1d9f07a4f7 100644 (file)
@@ -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() });
index 82e56fa0ae53d1b8145327c2cc42613dfdd32680..03635a964a210f9963aeefa60c0a2069c7f4fb68 100644 (file)
@@ -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:
index e058e2693c7fb008d712c42be9b7a0a3c11062d7..834bfe74d963314ab152954e1106881df26c15f0 100644 (file)
@@ -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);
     }
 }
 
index 783ff060b5d09e2cef9576c71b672c76bb527a25..70f3db8889d86afe25c9290dfcf12aefaf35ec6e 100644 (file)
@@ -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);