Async Poll: keep the size in the database
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 14 Mar 2019 11:08:47 +0000 (12:08 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:44 +0000 (10:58 +0100)
This was not required with 2.5 because a size of 0 was ignorted when comparing
size by the csync updater, to be compatible with very old version of the database.
But the we discovery will still think the file is changed if the database contains
a size of 0

src/common/syncjournaldb.cpp
src/common/syncjournaldb.h
src/libsync/owncloudpropagator.cpp
src/libsync/propagateupload.cpp

index 33f3f49ffb21397cb69eedd35210c0ebfc7ca868..e613358a63075b40158b138178a9c364c2e27ca4 100644 (file)
@@ -442,12 +442,13 @@ bool SyncJournalDb::checkConnect()
         return sqlFail("Create table blacklist", createQuery);
     }
 
-    createQuery.prepare("CREATE TABLE IF NOT EXISTS poll("
+    createQuery.prepare("CREATE TABLE IF NOT EXISTS async_poll("
                         "path VARCHAR(4096),"
                         "modtime INTEGER(8),"
+                        "filesize BIGINT,"
                         "pollpath VARCHAR(4096));");
     if (!createQuery.exec()) {
-        return sqlFail("Create table poll", createQuery);
+        return sqlFail("Create table async_poll", createQuery);
     }
 
     // create the selectivesync table.
@@ -1722,7 +1723,7 @@ QVector<SyncJournalDb::PollInfo> SyncJournalDb::getPollInfos()
     if (!checkConnect())
         return res;
 
-    SqlQuery query("SELECT path, modtime, pollpath FROM poll", _db);
+    SqlQuery query("SELECT path, modtime, filesize, pollpath FROM async_poll", _db);
 
     if (!query.exec()) {
         return res;
@@ -1732,7 +1733,8 @@ QVector<SyncJournalDb::PollInfo> SyncJournalDb::getPollInfos()
         PollInfo info;
         info._file = query.stringValue(0);
         info._modtime = query.int64Value(1);
-        info._url = query.stringValue(2);
+        info._fileSize = query.int64Value(2);
+        info._url = query.stringValue(3);
         res.append(info);
     }
 
@@ -1749,14 +1751,15 @@ void SyncJournalDb::setPollInfo(const SyncJournalDb::PollInfo &info)
 
     if (info._url.isEmpty()) {
         qCDebug(lcDb) << "Deleting Poll job" << info._file;
-        SqlQuery query("DELETE FROM poll WHERE path=?", _db);
+        SqlQuery query("DELETE FROM async_poll WHERE path=?", _db);
         query.bindValue(1, info._file);
         query.exec();
     } else {
-        SqlQuery query("INSERT OR REPLACE INTO poll (path, modtime, pollpath) VALUES( ? , ? , ? )", _db);
+        SqlQuery query("INSERT OR REPLACE INTO async_poll (path, modtime, filesize, pollpath) VALUES( ? , ? , ? , ? )", _db);
         query.bindValue(1, info._file);
         query.bindValue(2, info._modtime);
-        query.bindValue(3, info._url);
+        query.bindValue(3, info._fileSize);
+        query.bindValue(4, info._url);
         query.exec();
     }
 }
index 13596fb0a817a595b2bcfcc4ff2d9527413edfd1..cf0cf61a3717db7bafa23c2727e6669af3b7c07f 100644 (file)
@@ -114,6 +114,7 @@ public:
         QString _file; // The relative path of a file
         QString _url; // the poll url. (This pollinfo is invalid if _url is empty)
         qint64 _modtime; // The modtime of the file being uploaded
+        qint64 _fileSize;
     };
 
     DownloadInfo getDownloadInfo(const QString &file);
index a1d60eada09d2548458af656b68e963d790223cf..b8fd817ad8c5d5212a4076fdbfbc6c4c9f5c35ac 100644 (file)
@@ -1008,6 +1008,7 @@ void CleanupPollsJob::start()
     SyncFileItemPtr item(new SyncFileItem);
     item->_file = info._file;
     item->_modtime = info._modtime;
+    item->_size = info._fileSize;
     auto *job = new PollJob(_account, info._url, item, _journal, _localPath, this);
     connect(job, &PollJob::finishedSignal, this, &CleanupPollsJob::slotPollFinished);
     job->start();
index 47b6fc1d3f9e21d29375c667dde0cae0791ba183..77f4f73f72bba3a924db241b6c5807a0443eb835 100644 (file)
@@ -592,6 +592,7 @@ void PropagateUploadFileCommon::startPollJob(const QString &path)
     info._file = _item->_file;
     info._url = path;
     info._modtime = _item->_modtime;
+    info._fileSize = _item->_size;
     propagator()->_journal->setPollInfo(info);
     propagator()->_journal->commit("add poll info");
     propagator()->_activeJobList.append(this);