mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-28 07:54:49 +03:00
SyncJournalDB: Simplify code
This commit is contained in:
parent
e5e2ce2b22
commit
3556ed416c
3 changed files with 15 additions and 37 deletions
|
@ -595,7 +595,6 @@ void SyncEngine::startSync()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fileRecordCount = _journal->getFileRecordCount(); // this creates the DB if it does not exist yet
|
fileRecordCount = _journal->getFileRecordCount(); // this creates the DB if it does not exist yet
|
||||||
bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5();
|
|
||||||
|
|
||||||
if( fileRecordCount == -1 ) {
|
if( fileRecordCount == -1 ) {
|
||||||
qDebug() << "No way to create a sync journal!";
|
qDebug() << "No way to create a sync journal!";
|
||||||
|
@ -605,16 +604,7 @@ void SyncEngine::startSync()
|
||||||
// database creation error!
|
// database creation error!
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
_csync_ctx->read_remote_from_db = true;
|
||||||
* If we are upgrading from a client version older than 1.5 is found,
|
|
||||||
* we cannot read from the database because we need to fetch the files id and etags.
|
|
||||||
*/
|
|
||||||
if (fileRecordCount >= 1 && isUpdateFrom_1_5) {
|
|
||||||
qDebug() << "detected update from 1.5" << fileRecordCount << isUpdateFrom_1_5;
|
|
||||||
_csync_ctx->read_remote_from_db = false;
|
|
||||||
} else {
|
|
||||||
_csync_ctx->read_remote_from_db = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This tells csync to never read from the DB if it is empty
|
// This tells csync to never read from the DB if it is empty
|
||||||
// thereby speeding up the initial discovery significantly.
|
// thereby speeding up the initial discovery significantly.
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
|
SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
|
||||||
QObject(parent), _transaction(0), _possibleUpgradeFromMirall_1_5(false)
|
QObject(parent), _transaction(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
_dbFile = path;
|
_dbFile = path;
|
||||||
|
@ -272,15 +272,14 @@ bool SyncJournalDb::checkConnect()
|
||||||
return sqlFail("Create table version", createQuery);
|
return sqlFail("Create table version", createQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
_possibleUpgradeFromMirall_1_5 = false;
|
bool forceRemoteDiscovery = false;
|
||||||
bool possibleUpgradeFromMirall_1_8_0_or_1 = false;
|
|
||||||
|
|
||||||
SqlQuery versionQuery("SELECT major, minor, patch FROM version;", _db);
|
SqlQuery versionQuery("SELECT major, minor, patch FROM version;", _db);
|
||||||
if (!versionQuery.next()) {
|
if (!versionQuery.next()) {
|
||||||
// If there was no entry in the table, it means we are likely upgrading from 1.5
|
// If there was no entry in the table, it means we are likely upgrading from 1.5
|
||||||
if (!isNewDb) {
|
if (!isNewDb) {
|
||||||
qDebug() << Q_FUNC_INFO << "_possibleUpgradeFromMirall_1_5 detected!";
|
qDebug() << Q_FUNC_INFO << "possibleUpgradeFromMirall_1_5 detected!";
|
||||||
_possibleUpgradeFromMirall_1_5 = true;
|
forceRemoteDiscovery = true;
|
||||||
}
|
}
|
||||||
createQuery.prepare("INSERT INTO version VALUES (?1, ?2, ?3, ?4);");
|
createQuery.prepare("INSERT INTO version VALUES (?1, ?2, ?3, ?4);");
|
||||||
createQuery.bindValue(1, MIRALL_VERSION_MAJOR);
|
createQuery.bindValue(1, MIRALL_VERSION_MAJOR);
|
||||||
|
@ -296,7 +295,7 @@ bool SyncJournalDb::checkConnect()
|
||||||
|
|
||||||
if( major == 1 && minor == 8 && (patch == 0 || patch == 1) ) {
|
if( major == 1 && minor == 8 && (patch == 0 || patch == 1) ) {
|
||||||
qDebug() << Q_FUNC_INFO << "possibleUpgradeFromMirall_1_8_0_or_1 detected!";
|
qDebug() << Q_FUNC_INFO << "possibleUpgradeFromMirall_1_8_0_or_1 detected!";
|
||||||
possibleUpgradeFromMirall_1_8_0_or_1 = true;
|
forceRemoteDiscovery = true;
|
||||||
}
|
}
|
||||||
// Not comparing the BUILD id here, correct?
|
// Not comparing the BUILD id here, correct?
|
||||||
if( !(major == MIRALL_VERSION_MAJOR && minor == MIRALL_VERSION_MINOR && patch == MIRALL_VERSION_PATCH) ) {
|
if( !(major == MIRALL_VERSION_MAJOR && minor == MIRALL_VERSION_MINOR && patch == MIRALL_VERSION_PATCH) ) {
|
||||||
|
@ -323,7 +322,15 @@ bool SyncJournalDb::checkConnect()
|
||||||
qDebug() << "WARN: Failed to update the database structure!";
|
qDebug() << "WARN: Failed to update the database structure!";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (possibleUpgradeFromMirall_1_8_0_or_1) {
|
/*
|
||||||
|
* If we are upgrading from a client version older than 1.5 is found,
|
||||||
|
* we cannot read from the database because we need to fetch the files id and etags.
|
||||||
|
*
|
||||||
|
* If 1.8.0 caused missing data in the local tree, so we also don't read from DB
|
||||||
|
* to get back the files that were gone.
|
||||||
|
* In 1.8.1 we had a fix to re-get the data, but this one here is better
|
||||||
|
*/
|
||||||
|
if (forceRemoteDiscovery) {
|
||||||
qDebug() << "Forcing remote re-discovery by deleting folder Etags";
|
qDebug() << "Forcing remote re-discovery by deleting folder Etags";
|
||||||
SqlQuery deleteRemoteFolderEtagsQuery(_db);
|
SqlQuery deleteRemoteFolderEtagsQuery(_db);
|
||||||
deleteRemoteFolderEtagsQuery.prepare("UPDATE metadata SET md5=NULL WHERE type=2;");
|
deleteRemoteFolderEtagsQuery.prepare("UPDATE metadata SET md5=NULL WHERE type=2;");
|
||||||
|
@ -420,7 +427,6 @@ void SyncJournalDb::close()
|
||||||
_deleteFileRecordRecursively.reset(0);
|
_deleteFileRecordRecursively.reset(0);
|
||||||
_getErrorBlacklistQuery.reset(0);
|
_getErrorBlacklistQuery.reset(0);
|
||||||
_setErrorBlacklistQuery.reset(0);
|
_setErrorBlacklistQuery.reset(0);
|
||||||
_possibleUpgradeFromMirall_1_5 = false;
|
|
||||||
|
|
||||||
_db.close();
|
_db.close();
|
||||||
_avoidReadFromDbOnNextSyncFilter.clear();
|
_avoidReadFromDbOnNextSyncFilter.clear();
|
||||||
|
@ -766,10 +772,6 @@ bool SyncJournalDb::postSyncCleanup(const QSet<QString>& filepathsToKeep,
|
||||||
// Incoroporate results back into main DB
|
// Incoroporate results back into main DB
|
||||||
walCheckpoint();
|
walCheckpoint();
|
||||||
|
|
||||||
if (_possibleUpgradeFromMirall_1_5) {
|
|
||||||
_possibleUpgradeFromMirall_1_5 = false; // should be handled now
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1332,13 +1334,6 @@ bool SyncJournalDb::isConnected()
|
||||||
return checkConnect();
|
return checkConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyncJournalDb::isUpdateFrom_1_5()
|
|
||||||
{
|
|
||||||
QMutexLocker lock(&_mutex);
|
|
||||||
checkConnect();
|
|
||||||
return _possibleUpgradeFromMirall_1_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const SyncJournalDb::DownloadInfo & lhs,
|
bool operator==(const SyncJournalDb::DownloadInfo & lhs,
|
||||||
const SyncJournalDb::DownloadInfo & rhs)
|
const SyncJournalDb::DownloadInfo & rhs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,12 +113,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell the sync engine if we need to disable the fetch from db to be sure that the fileid
|
|
||||||
* are updated.
|
|
||||||
*/
|
|
||||||
bool isUpdateFrom_1_5();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool updateDatabaseStructure();
|
bool updateDatabaseStructure();
|
||||||
bool updateMetadataTableStructure();
|
bool updateMetadataTableStructure();
|
||||||
|
@ -134,7 +128,6 @@ private:
|
||||||
QString _dbFile;
|
QString _dbFile;
|
||||||
QMutex _mutex; // Public functions are protected with the mutex.
|
QMutex _mutex; // Public functions are protected with the mutex.
|
||||||
int _transaction;
|
int _transaction;
|
||||||
bool _possibleUpgradeFromMirall_1_5;
|
|
||||||
QScopedPointer<SqlQuery> _getFileRecordQuery;
|
QScopedPointer<SqlQuery> _getFileRecordQuery;
|
||||||
QScopedPointer<SqlQuery> _setFileRecordQuery;
|
QScopedPointer<SqlQuery> _setFileRecordQuery;
|
||||||
QScopedPointer<SqlQuery> _getDownloadInfoQuery;
|
QScopedPointer<SqlQuery> _getDownloadInfoQuery;
|
||||||
|
|
Loading…
Reference in a new issue