Use QDateTime::currentDateTimeUtc instead of the non utc version
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 25 Sep 2017 09:49:11 +0000 (11:49 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 5 Oct 2017 20:01:37 +0000 (22:01 +0200)
QDateTime::currentDateTime is terribly slow.

12 files changed:
src/common/utility.cpp
src/gui/syncrunfilelog.cpp
src/libsync/cookiejar.cpp
src/libsync/logger.cpp
src/libsync/owncloudpropagator.cpp
src/libsync/propagatedownload.cpp
src/libsync/propagateupload.cpp
src/libsync/syncengine.cpp
src/libsync/syncresult.cpp
test/mockserver/httpserver.cpp
test/syncenginetestutils.h
test/testsyncengine.cpp

index 460435f1d639649f666eb1a78141b65598486a44..212433c75759fdbe18fd16ba821af5d7c513be9b 100644 (file)
@@ -465,7 +465,7 @@ static const char STOPWATCH_END_TAG[] = "_STOPWATCH_END";
 
 void Utility::StopWatch::start()
 {
-    _startTime = QDateTime::currentDateTime();
+    _startTime = QDateTime::currentDateTimeUtc();
     _timer.start();
 }
 
index 51396cbb0f6480dcac4f2e81a22843a334fc8a6c..9d4a06d7fe59a2dbec5bdee27f98f4f4c1d0f764 100644 (file)
@@ -127,7 +127,7 @@ void SyncRunFileLog::start(const QString &folderPath)
 
     _totalDuration.start();
     _lapDuration.start();
-    _out << "#=#=#=# Syncrun started " << dateTimeStr(QDateTime::currentDateTime()) << endl;
+    _out << "#=#=#=# Syncrun started " << dateTimeStr(QDateTime::currentDateTimeUtc()) << endl;
 }
 
 void SyncRunFileLog::logItem(const SyncFileItem &item)
@@ -172,14 +172,14 @@ void SyncRunFileLog::logItem(const SyncFileItem &item)
 
 void SyncRunFileLog::logLap(const QString &name)
 {
-    _out << "#=#=#=#=# " << name << " " << dateTimeStr(QDateTime::currentDateTime())
+    _out << "#=#=#=#=# " << name << " " << dateTimeStr(QDateTime::currentDateTimeUtc())
          << " (last step: " << _lapDuration.restart() << " msec"
          << ", total: " << _totalDuration.elapsed() << " msec)" << endl;
 }
 
 void SyncRunFileLog::finish()
 {
-    _out << "#=#=#=# Syncrun finished " << dateTimeStr(QDateTime::currentDateTime())
+    _out << "#=#=#=# Syncrun finished " << dateTimeStr(QDateTime::currentDateTimeUtc())
          << " (last step: " << _lapDuration.elapsed() << " msec"
          << ", total: " << _totalDuration.elapsed() << " msec)" << endl;
     _file->close();
index 4af34d5e74812dfa7f7edc582fd68431c85dc5be..a15ac87d1fb5f0610391adbcf6bc342904b7c65e 100644 (file)
@@ -124,7 +124,7 @@ QList<QNetworkCookie> CookieJar::removeExpired(const QList<QNetworkCookie> &cook
 {
     QList<QNetworkCookie> updatedList;
     foreach (const QNetworkCookie &cookie, cookies) {
-        if (cookie.expirationDate() > QDateTime::currentDateTime() && !cookie.isSessionCookie()) {
+        if (cookie.expirationDate() > QDateTime::currentDateTimeUtc() && !cookie.isSessionCookie()) {
             updatedList << cookie;
         }
     }
index a0fe727e8538e00a8674ec97ccb334ea7942640c..31afbbe8c6bb1f37d7cc346a5bf9fba299453ea5 100644 (file)
@@ -152,7 +152,7 @@ void Logger::mirallLog(const QString &message)
 {
     Log log_;
     log_.source = Log::Occ;
-    log_.timeStamp = QDateTime::currentDateTime();
+    log_.timeStamp = QDateTime::currentDateTimeUtc();
     log_.message = message;
 
     Logger::instance()->log(log_);
@@ -236,7 +236,7 @@ void Logger::enterNextLogFile()
             QDir::Files);
         QRegExp rx("owncloud.log.(\\d+)");
         uint maxNumber = 0;
-        QDateTime now = QDateTime::currentDateTime();
+        QDateTime now = QDateTime::currentDateTimeUtc();
         foreach (const QString &s, files) {
             if (rx.exactMatch(s)) {
                 maxNumber = qMax(maxNumber, rx.cap(1).toUInt());
index 4673e9b340ec6294d6cd7c66eadf979c35a1ff37..281f34548e95f2c2d74d616aeef65ec28fb12b9d 100644 (file)
@@ -138,7 +138,7 @@ static SyncJournalErrorBlacklistRecord createBlacklistEntry(
     entry._errorString = item._errorString;
     entry._lastTryModtime = item._modtime;
     entry._lastTryEtag = item._etag;
-    entry._lastTryTime = Utility::qDateTimeToTime_t(QDateTime::currentDateTime());
+    entry._lastTryTime = Utility::qDateTimeToTime_t(QDateTime::currentDateTimeUtc());
     entry._renameTarget = item._renameTarget;
     entry._retryCount = old._retryCount + 1;
 
@@ -309,7 +309,7 @@ bool PropagateItemJob::checkForProblemsWithShared(int httpStatusCode, const QStr
 
                 // HACK to avoid continuation: See task #1448:  We do not know the _modtime from the
                 //  server, at this point, so just set the current one. (rather than the one locally)
-                downloadItem->_modtime = Utility::qDateTimeToTime_t(QDateTime::currentDateTime());
+                downloadItem->_modtime = Utility::qDateTimeToTime_t(QDateTime::currentDateTimeUtc());
             } else {
                 // the file was removed or renamed, just recover the old one
                 downloadItem->_instruction = CSYNC_INSTRUCTION_SYNC;
index 6466d13b61e1e834409ed54bad3d2c7b7933f504..11207d2adb3e5ccb09df9a68333fa17a5b0f8fcd 100644 (file)
@@ -673,7 +673,7 @@ namespace { // Anonymous namespace for the recall feature
             dotLocation = recallFileName.size();
         }
 
-        QString timeString = QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss");
+        QString timeString = QDateTime::currentDateTimeUtc().toString("yyyyMMdd-hhmmss");
         recallFileName.insert(dotLocation, "_.sys.admin#recall#-" + timeString);
 
         return recallFileName;
index 5ba8a5c6b3060451ff65339f1d3fe1a9f4591619..eca04267891637408a7dc819bf193f208016c87d 100644 (file)
@@ -53,7 +53,7 @@ Q_LOGGING_CATEGORY(lcPropagateUpload, "sync.propagator.upload", QtInfoMsg)
 static bool fileIsStillChanging(const SyncFileItem &item)
 {
     const QDateTime modtime = Utility::qDateTimeFromTime_t(item._modtime);
-    const qint64 msSinceMod = modtime.msecsTo(QDateTime::currentDateTime());
+    const qint64 msSinceMod = modtime.msecsTo(QDateTime::currentDateTimeUtc());
 
     return msSinceMod < SyncEngine::minimumFileAgeForUpload
         // if the mtime is too much in the future we *do* upload the file
index 2c71ae7346a1a0e56e7902aa141b34f871f923eb..80d36d4be3b4ffd2d01e8cf580a7c59046aed3f1 100644 (file)
@@ -219,7 +219,7 @@ bool SyncEngine::checkErrorBlacklisting(SyncFileItem &item)
     item._hasBlacklistEntry = true;
 
     // If duration has expired, it's not blacklisted anymore
-    time_t now = Utility::qDateTimeToTime_t(QDateTime::currentDateTime());
+    time_t now = Utility::qDateTimeToTime_t(QDateTime::currentDateTimeUtc());
     if (now >= entry._lastTryTime + entry._ignoreDuration) {
         qCInfo(lcEngine) << "blacklist entry for " << item._file << " has expired!";
         return false;
index 52ce018d14f3169a1c2d062b8b7b6533eeef0f53..c2aeb24ed12f7f57ea2a144eb3d9eed81adcf1e7 100644 (file)
@@ -85,7 +85,7 @@ QString SyncResult::statusString() const
 void SyncResult::setStatus(Status stat)
 {
     _status = stat;
-    _syncTime = QDateTime::currentDateTime();
+    _syncTime = QDateTime::currentDateTimeUtc();
 }
 
 QDateTime SyncResult::syncTime() const
index c1f2a0cee5939a56ccde5eba517ab6d77a02a499..fbc24e8474cac6a8bf2660d6a7cf59ce0636e7d6 100644 (file)
@@ -32,7 +32,7 @@ void HttpServer::readClient()
                 "Content-Type: text/html; charset=\"utf-8\"\r\n"
                 "\r\n"
                 "<h1>Nothing to see here</h1>\n"
-                << QDateTime::currentDateTime().toString() << "\n";
+                << QDateTime::currentDateTimeUtc().toString() << "\n";
             socket->close();
 
             QtServiceBase::instance()->logMessage("Wrote to client");
index cabac73bfa664d5ee6e90bc5de28c90d248f51dc..9253b6285a78f691d5485175ccfa596fcd36bef2 100644 (file)
@@ -41,7 +41,7 @@ inline QString getFilePathFromUrl(const QUrl &url) {
 
 
 inline QString generateEtag() {
-    return QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch(), 16);
+    return QString::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch(), 16);
 }
 inline QByteArray generateFileId() {
     return QByteArray::number(qrand(), 16);
@@ -97,7 +97,7 @@ public:
         file.write(buf.data(), size % buf.size());
         file.close();
         // Set the mtime 30 seconds in the past, for some tests that need to make sure that the mtime differs.
-        OCC::FileSystem::setModTime(file.fileName(), OCC::Utility::qDateTimeToTime_t(QDateTime::currentDateTime().addSecs(-30)));
+        OCC::FileSystem::setModTime(file.fileName(), OCC::Utility::qDateTimeToTime_t(QDateTime::currentDateTimeUtc().addSecs(-30)));
         QCOMPARE(file.size(), size);
     }
     void setContents(const QString &relativePath, char contentChar) override {
index a4c4c5be4f13230c2226c13f5b3a1704b2a1072a..169c2e6fb1b468279e8ec0fdf9143480d1ce93ac 100644 (file)
@@ -358,7 +358,7 @@ private slots:
         FileInfo &remoteInfo = dynamic_cast<FileInfo &>(fakeFolder.remoteModifier());
 
         // Base mtime with no ms content (filesystem is seconds only)
-        auto mtime = QDateTime::currentDateTime().addDays(-4);
+        auto mtime = QDateTime::currentDateTimeUtc().addDays(-4);
         mtime.setMSecsSinceEpoch(mtime.toMSecsSinceEpoch() / 1000 * 1000);
 
         // Conflict: Same content, mtime, but no server checksum
@@ -414,9 +414,9 @@ private slots:
      */
     void testSyncFileItemProperties()
     {
-        auto initialMtime = QDateTime::currentDateTime().addDays(-7);
-        auto changedMtime = QDateTime::currentDateTime().addDays(-4);
-        auto changedMtime2 = QDateTime::currentDateTime().addDays(-3);
+        auto initialMtime = QDateTime::currentDateTimeUtc().addDays(-7);
+        auto changedMtime = QDateTime::currentDateTimeUtc().addDays(-4);
+        auto changedMtime2 = QDateTime::currentDateTimeUtc().addDays(-3);
 
         // Base mtime with no ms content (filesystem is seconds only)
         initialMtime.setMSecsSinceEpoch(initialMtime.toMSecsSinceEpoch() / 1000 * 1000);