Skip to content

Commit ce4db72

Browse files
qoolenilsding
authored andcommitted
perf(rename): cache fileExists results in PropagateLocalRename::start
PropagateLocalRename::start was calling FileSystem::fileExists up to five times across the same three paths in a row. Each call is a filesystem stat. Cache the three results into local bools and reuse them. Side benefit: the Q_ASSERT and the two qCDebug log lines now match the bool values used in fileAlreadyMoved, eliminating the chance of the assert and the log disagreeing if the filesystem state changes mid-function. Signed-off-by: Qoole <2862661+qoole@users.noreply.github.com>
1 parent 7dacf3e commit ce4db72

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/libsync/propagatorjobs.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,10 @@ void PropagateLocalRename::start()
349349
const auto targetFile = propagator()->fullLocalPath(_item->_renameTarget);
350350
const auto originalFile = propagator()->fullLocalPath(_item->_originalFile);
351351

352-
const auto fileAlreadyMoved = (!FileSystem::fileExists(originalFile) || !FileSystem::fileExists(existingFile))&& FileSystem::fileExists(targetFile);
352+
const auto origExists = FileSystem::fileExists(originalFile);
353+
const auto existingExists = FileSystem::fileExists(existingFile);
354+
const auto targetExists = FileSystem::fileExists(targetFile);
355+
const auto fileAlreadyMoved = (!origExists || !existingExists) && targetExists;
353356
auto pinState = OCC::PinState::Unspecified;
354357
if (!fileAlreadyMoved) {
355358
auto pinStateResult = vfs->pinState(propagator()->adjustRenamedPath(_item->_file));
@@ -361,9 +364,9 @@ void PropagateLocalRename::start()
361364
// if the file is a file underneath a moved dir, the _item->file is equal
362365
// to _item->renameTarget and the file is not moved as a result.
363366
qCDebug(lcPropagateLocalRename) << _item->_file << _item->_renameTarget << _item->_originalFile << previousNameInDb << (fileAlreadyMoved ? "original file has already moved" : "original file is still there");
364-
qCDebug(lcPropagateLocalRename()) << (FileSystem::fileExists(originalFile) ? "original file exists" : "original file is missing") << originalFile << _item->_originalFile;
365-
qCDebug(lcPropagateLocalRename()) << (FileSystem::fileExists(existingFile) ? "existing file exists" : "existing file is missing") << existingFile << previousNameInDb;
366-
Q_ASSERT(FileSystem::fileExists(propagator()->fullLocalPath(_item->_originalFile)) || FileSystem::fileExists(existingFile));
367+
qCDebug(lcPropagateLocalRename()) << (origExists ? "original file exists" : "original file is missing") << originalFile << _item->_originalFile;
368+
qCDebug(lcPropagateLocalRename()) << (existingExists ? "existing file exists" : "existing file is missing") << existingFile << previousNameInDb;
369+
Q_ASSERT(origExists || existingExists);
367370
if (_item->_file != _item->_renameTarget) {
368371
propagator()->reportProgress(*_item, 0);
369372
qCDebug(lcPropagateLocalRename) << "MOVE " << existingFile << " => " << targetFile;

0 commit comments

Comments
 (0)