From: Olivier Goffart Date: Tue, 6 Nov 2018 09:45:22 +0000 (+0100) Subject: Optimisation: Add a cache SyncJournalDb::mapChecksumType X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~424 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d6a0290058660f60a415e753d59e57e56f0c2c0d;p=nextcloud-desktop.git Optimisation: Add a cache SyncJournalDb::mapChecksumType No need to do two sql query for something that's always the same and there are very few checksum types --- diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index 3234b0067..2d900f8ae 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -1901,6 +1901,10 @@ int SyncJournalDb::mapChecksumType(const QByteArray &checksumType) return 0; } + auto it = _checksymTypeCache.find(checksumType); + if (it != _checksymTypeCache.end()) + return *it; + // Ensure the checksum type is in the db if (!_insertChecksumTypeQuery.initOrReset(QByteArrayLiteral("INSERT OR IGNORE INTO checksumtype (name) VALUES (?1)"), _db)) return 0; @@ -1921,7 +1925,9 @@ int SyncJournalDb::mapChecksumType(const QByteArray &checksumType) qCWarning(lcDb) << "No checksum type mapping found for" << checksumType; return 0; } - return _getChecksumTypeIdQuery.intValue(0); + auto value = _getChecksumTypeIdQuery.intValue(0); + _checksymTypeCache[checksumType] = value; + return value; } QByteArray SyncJournalDb::dataFingerprint() diff --git a/src/common/syncjournaldb.h b/src/common/syncjournaldb.h index 12d2871ca..01e66734b 100644 --- a/src/common/syncjournaldb.h +++ b/src/common/syncjournaldb.h @@ -272,6 +272,7 @@ private: SqlDatabase _db; QString _dbFile; QMutex _mutex; // Public functions are protected with the mutex. + QMap _checksymTypeCache; int _transaction; bool _metadataTableIsEmpty;