SyncJournalDB: Simplify code

This commit is contained in:
Markus Goetz 2015-05-13 13:15:53 +02:00
parent e5e2ce2b22
commit 3556ed416c
3 changed files with 15 additions and 37 deletions

View file

@ -595,7 +595,6 @@ void SyncEngine::startSync()
#endif
fileRecordCount = _journal->getFileRecordCount(); // this creates the DB if it does not exist yet
bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5();
if( fileRecordCount == -1 ) {
qDebug() << "No way to create a sync journal!";
@ -605,16 +604,7 @@ void SyncEngine::startSync()
// database creation error!
}
/*
* 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;
}
_csync_ctx->read_remote_from_db = true;
// This tells csync to never read from the DB if it is empty
// thereby speeding up the initial discovery significantly.

View file

@ -30,7 +30,7 @@
namespace OCC {
SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
QObject(parent), _transaction(0), _possibleUpgradeFromMirall_1_5(false)
QObject(parent), _transaction(0)
{
_dbFile = path;
@ -272,15 +272,14 @@ bool SyncJournalDb::checkConnect()
return sqlFail("Create table version", createQuery);
}
_possibleUpgradeFromMirall_1_5 = false;
bool possibleUpgradeFromMirall_1_8_0_or_1 = false;
bool forceRemoteDiscovery = false;
SqlQuery versionQuery("SELECT major, minor, patch FROM version;", _db);
if (!versionQuery.next()) {
// If there was no entry in the table, it means we are likely upgrading from 1.5
if (!isNewDb) {
qDebug() << Q_FUNC_INFO << "_possibleUpgradeFromMirall_1_5 detected!";
_possibleUpgradeFromMirall_1_5 = true;
qDebug() << Q_FUNC_INFO << "possibleUpgradeFromMirall_1_5 detected!";
forceRemoteDiscovery = true;
}
createQuery.prepare("INSERT INTO version VALUES (?1, ?2, ?3, ?4);");
createQuery.bindValue(1, MIRALL_VERSION_MAJOR);
@ -296,7 +295,7 @@ bool SyncJournalDb::checkConnect()
if( major == 1 && minor == 8 && (patch == 0 || patch == 1) ) {
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?
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!";
}
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";
SqlQuery deleteRemoteFolderEtagsQuery(_db);
deleteRemoteFolderEtagsQuery.prepare("UPDATE metadata SET md5=NULL WHERE type=2;");
@ -420,7 +427,6 @@ void SyncJournalDb::close()
_deleteFileRecordRecursively.reset(0);
_getErrorBlacklistQuery.reset(0);
_setErrorBlacklistQuery.reset(0);
_possibleUpgradeFromMirall_1_5 = false;
_db.close();
_avoidReadFromDbOnNextSyncFilter.clear();
@ -766,10 +772,6 @@ bool SyncJournalDb::postSyncCleanup(const QSet<QString>& filepathsToKeep,
// Incoroporate results back into main DB
walCheckpoint();
if (_possibleUpgradeFromMirall_1_5) {
_possibleUpgradeFromMirall_1_5 = false; // should be handled now
}
return true;
}
@ -1332,13 +1334,6 @@ bool SyncJournalDb::isConnected()
return checkConnect();
}
bool SyncJournalDb::isUpdateFrom_1_5()
{
QMutexLocker lock(&_mutex);
checkConnect();
return _possibleUpgradeFromMirall_1_5;
}
bool operator==(const SyncJournalDb::DownloadInfo & lhs,
const SyncJournalDb::DownloadInfo & rhs)
{

View file

@ -113,12 +113,6 @@ public:
*/
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:
bool updateDatabaseStructure();
bool updateMetadataTableStructure();
@ -134,7 +128,6 @@ private:
QString _dbFile;
QMutex _mutex; // Public functions are protected with the mutex.
int _transaction;
bool _possibleUpgradeFromMirall_1_5;
QScopedPointer<SqlQuery> _getFileRecordQuery;
QScopedPointer<SqlQuery> _setFileRecordQuery;
QScopedPointer<SqlQuery> _getDownloadInfoQuery;