Skip to content

Commit 0de37dc

Browse files
committed
perf: cache the selective sync list in the journal
getSelectiveSyncList() runs a full query and materializes the whole list on every call, and Folder::warnOnNewExcludedItem() calls it once per file added to the sync folder. The list only changes when the user edits the selective sync configuration, so keep it in memory and drop it in setSelectiveSyncList(), the only writer of the table, and on close(). Signed-off-by: Felipe Tumonis <ftumonis@gmail.com>
1 parent 30af271 commit 0de37dc

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/common/syncjournaldb.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ void SyncJournalDb::close()
703703

704704
_db.close();
705705
clearEtagStorageFilter();
706+
_selectiveSyncListCache.clear();
706707
_metadataTableIsEmpty = false;
707708
}
708709

@@ -2380,6 +2381,12 @@ QStringList SyncJournalDb::getSelectiveSyncList(SyncJournalDb::SelectiveSyncList
23802381
return result;
23812382
}
23822383

2384+
const auto cached = _selectiveSyncListCache.constFind(int(type));
2385+
if (cached != _selectiveSyncListCache.constEnd()) {
2386+
*ok = true;
2387+
return *cached;
2388+
}
2389+
23832390
const auto query = _queryManager.get(PreparedSqlQueryManager::GetSelectiveSyncListQuery, QByteArrayLiteral("SELECT path FROM selectivesync WHERE type=?1"), _db);
23842391
if (!query) {
23852392
qCWarning(lcDb) << "database error:" << query->error();
@@ -2408,6 +2415,8 @@ QStringList SyncJournalDb::getSelectiveSyncList(SyncJournalDb::SelectiveSyncList
24082415
}
24092416
*ok = true;
24102417

2418+
_selectiveSyncListCache.insert(int(type), result);
2419+
24112420
return result;
24122421
}
24132422

@@ -2418,6 +2427,10 @@ void SyncJournalDb::setSelectiveSyncList(SyncJournalDb::SelectiveSyncListType ty
24182427
return;
24192428
}
24202429

2430+
// Dropped rather than replaced with `list`: getSelectiveSyncList() hands out entries with a
2431+
// trailing slash, which is added on read, not on write.
2432+
_selectiveSyncListCache.remove(int(type));
2433+
24212434
startTransaction();
24222435

24232436
//first, delete all entries of this type

src/common/syncjournaldb.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,15 @@ public slots:
431431
int _transaction = 0;
432432
bool _metadataTableIsEmpty = false;
433433

434+
/* Cache for getSelectiveSyncList(), keyed by SelectiveSyncListType.
435+
*
436+
* The list is read once per file in some hot paths (see Folder::warnOnNewExcludedItem) while
437+
* changing only when the user edits the selective sync configuration, so it is kept here
438+
* rather than re-queried. Invalidated by setSelectiveSyncList() -- the only writer of the
439+
* selectivesync table -- and on close().
440+
*/
441+
QHash<int, QStringList> _selectiveSyncListCache;
442+
434443
/* Storing etags to these folders, or their parent folders, is filtered out.
435444
*
436445
* When schedulePathForRemoteDiscovery() is called some etags to _invalid_ in the

0 commit comments

Comments
 (0)