From f4929e849e46cb53ea2ac81b24fef73ce50d5415 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 4 Oct 2013 14:44:57 +0200 Subject: [PATCH] CsyncThread: Activate recursive PROPFIND --- src/mirall/csyncthread.cpp | 12 ++++++++++++ src/mirall/syncjournaldb.cpp | 26 ++++++++++++++++++++++++++ src/mirall/syncjournaldb.h | 2 ++ 3 files changed, 40 insertions(+) diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 78f05df819..2a3e3b00b5 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -335,6 +335,18 @@ void CSyncThread::startSync() // maybe move this somewhere else where it can influence a running sync? MirallConfigFile cfg; + int fileRecordCount = 0; + if (!_journal->exists()) { + qDebug() << "=====sync looks new (no DB exists), activating recursive PROPFIND if csync supports it"; + bool no_recursive_propfind = false; + csync_set_module_property(_csync_ctx, "no_recursive_propfind", &no_recursive_propfind); + } else if ((fileRecordCount = _journal->getFileRecordCount()) < 50) { + qDebug() << "=====sync DB has only" << fileRecordCount << "items, enable recursive PROPFIND if csync supports it"; + bool no_recursive_propfind = false; + csync_set_module_property(_csync_ctx, "no_recursive_propfind", &no_recursive_propfind); + } else { + qDebug() << "=====sync with existing DB"; + } csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); csync_set_userdata(_csync_ctx, this); diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp index 2d4a7410f3..d3c71a5310 100644 --- a/src/mirall/syncjournaldb.cpp +++ b/src/mirall/syncjournaldb.cpp @@ -38,6 +38,11 @@ SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) : _dbFile.append(".csync_journal.db"); } +bool SyncJournalDb::exists() +{ + return (!_dbFile.isEmpty() && QFile::exists(_dbFile)); +} + bool SyncJournalDb::checkConnect() { if( _db.isOpen() ) { @@ -225,5 +230,26 @@ SyncJournalFileRecord SyncJournalDb::getFileRecord( const QString& filename ) return rec; } +int SyncJournalDb::getFileRecordCount() +{ + if( !checkConnect() ) + return 0; + + QSqlQuery query("SELECT COUNT(*) FROM metadata" , _db); + + if (!query.exec()) { + QString err = query.lastError().text(); + qDebug() << "Error creating prepared statement: " << query.lastQuery() << ", Error:" << err;; + return 0; + } + + if (query.next()) { + int count = query.value(0).toInt(); + return count; + } + + return 0; +} + } // namespace Mirall diff --git a/src/mirall/syncjournaldb.h b/src/mirall/syncjournaldb.h index 566db94902..3da2caf708 100644 --- a/src/mirall/syncjournaldb.h +++ b/src/mirall/syncjournaldb.h @@ -30,8 +30,10 @@ public: bool setFileRecord( const SyncJournalFileRecord& record ); bool deleteFileRecord( const QString& filename ); + int getFileRecordCount(); QSqlDatabase *getDB(){ return &_db; } + bool exists(); bool checkConnect(); int64_t getPHash(const QString& ) const;