From b6140611fab29a958c14cd807e7db61576ebcbec Mon Sep 17 00:00:00 2001 From: alex-z Date: Thu, 21 Sep 2023 15:49:23 +0200 Subject: [PATCH] Optimize CaseConflictRecords search in local DB during the sync. Signed-off-by: alex-z --- src/common/syncjournaldb.cpp | 8 ++++++++ src/libsync/discovery.cpp | 6 +++++- src/libsync/discoveryphase.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index c277f04602359..e8c1f55619194 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -824,6 +824,14 @@ bool SyncJournalDb::updateMetadataTableStructure() addColumn(QStringLiteral("lockTime"), QStringLiteral("INTEGER")); addColumn(QStringLiteral("lockTimeout"), QStringLiteral("INTEGER")); + SqlQuery query(_db); + query.prepare("CREATE INDEX IF NOT EXISTS caseconflicts_basePath ON caseconflicts(basePath);"); + if (!query.exec()) { + sqlFail(QStringLiteral("caseconflictsTableStructure: create index basePath"), query); + return re = false; + } + commitInternal(QStringLiteral("update database structure: add basePath index")); + return re; } diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 669d9f5c7583b..64190b6082382 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -76,6 +76,8 @@ void ProcessDirectoryJob::start() { qCInfo(lcDisco) << "STARTING" << _currentFolder._server << _queryServer << _currentFolder._local << _queryLocal; + _discoveryData->_noCaseConflictRecordsInDb = _discoveryData->_statedb->caseClashConflictRecordPaths().isEmpty(); + if (_queryServer == NormalQuery) { _serverJob = startAsyncServerQuery(); } else { @@ -799,7 +801,9 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(const SyncFileItemPtr &it item->_modtime = serverEntry.modtime; item->_size = serverEntry.size; - const auto conflictRecord = _discoveryData->_statedb->caseConflictRecordByBasePath(item->_file); + const auto conflictRecord = _discoveryData->_noCaseConflictRecordsInDb + ? ConflictRecord{} : + _discoveryData->_statedb->caseConflictRecordByBasePath(item->_file); if (conflictRecord.isValid() && QString::fromUtf8(conflictRecord.path).contains(QStringLiteral("(case clash from"))) { qCInfo(lcDisco) << "should ignore" << item->_file << "has already a case clash conflict record" << conflictRecord.path; diff --git a/src/libsync/discoveryphase.h b/src/libsync/discoveryphase.h index 6c22db3a58e7d..561e9ee9f08d6 100644 --- a/src/libsync/discoveryphase.h +++ b/src/libsync/discoveryphase.h @@ -321,6 +321,8 @@ class DiscoveryPhase : public QObject bool _hasUploadErrorItems = false; bool _hasDownloadRemovedItems = false; + bool _noCaseConflictRecordsInDb = false; + signals: void fatalError(const QString &errorString, const OCC::ErrorCategory errorCategory); void itemDiscovered(const OCC::SyncFileItemPtr &item);