Sync: optimize by removing setFileRecordMetadata

Inh most case we already have a record from before, so avoid doing a useless
lookup in the database.
In owncloudpropagator.cpp, directories do not have a checksum so no need
to call a function that preserves it
This commit is contained in:
Olivier Goffart 2018-11-06 10:30:33 +01:00 committed by Kevin Ottens
parent 416a0b3482
commit 69de2d5180
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
6 changed files with 8 additions and 35 deletions

View file

@ -1297,31 +1297,6 @@ bool SyncJournalDb::updateLocalMetadata(const QString &filename,
return _setFileRecordLocalMetadataQuery.exec(); return _setFileRecordLocalMetadataQuery.exec();
} }
bool SyncJournalDb::setFileRecordMetadata(const SyncJournalFileRecord &record)
{
SyncJournalFileRecord existing;
if (!getFileRecord(record._path, &existing))
return false;
// If there's no existing record, just insert the new one.
if (!existing.isValid()) {
return setFileRecord(record);
}
// Update the metadata on the existing record.
existing._inode = record._inode;
existing._modtime = record._modtime;
existing._type = record._type;
existing._etag = record._etag;
existing._fileId = record._fileId;
existing._remotePerm = record._remotePerm;
existing._fileSize = record._fileSize;
existing._serverHasIgnoredFiles = record._serverHasIgnoredFiles;
existing._e2eMangledName = record._e2eMangledName;
existing._isE2eEncrypted = record._isE2eEncrypted;
return setFileRecord(existing);
}
static void toDownloadInfo(SqlQuery &query, SyncJournalDb::DownloadInfo *res) static void toDownloadInfo(SqlQuery &query, SyncJournalDb::DownloadInfo *res)
{ {
bool ok = true; bool ok = true;

View file

@ -64,9 +64,6 @@ public:
bool listFilesInPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback); bool listFilesInPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback);
bool setFileRecord(const SyncJournalFileRecord &record); bool setFileRecord(const SyncJournalFileRecord &record);
/// Like setFileRecord, but preserves checksums
bool setFileRecordMetadata(const SyncJournalFileRecord &record);
bool deleteFileRecord(const QString &filename, bool recursively = false); bool deleteFileRecord(const QString &filename, bool recursively = false);
bool updateFileRecordChecksum(const QString &filename, bool updateFileRecordChecksum(const QString &filename,
const QByteArray &contentChecksum, const QByteArray &contentChecksum,

View file

@ -884,7 +884,7 @@ void ProcessDirectoryJob::processFileConflict(const SyncFileItemPtr &item, Proce
rec._fileSize = serverEntry.size; rec._fileSize = serverEntry.size;
rec._remotePerm = serverEntry.remotePerm; rec._remotePerm = serverEntry.remotePerm;
rec._checksumHeader = serverEntry.checksumHeader; rec._checksumHeader = serverEntry.checksumHeader;
_discoveryData->_statedb->setFileRecordMetadata(rec); _discoveryData->_statedb->setFileRecord(rec);
} }
return; return;
} }

View file

@ -967,7 +967,7 @@ void PropagateDirectory::slotSubJobsFinished(SyncFileItem::Status status)
} }
} }
SyncJournalFileRecord record = _item->toSyncJournalFileRecordWithInode(propagator()->_localDir + _item->_file); SyncJournalFileRecord record = _item->toSyncJournalFileRecordWithInode(propagator()->_localDir + _item->_file);
bool ok = propagator()->_journal->setFileRecordMetadata(record); bool ok = propagator()->_journal->setFileRecord(record);
if (!ok) { if (!ok) {
status = _item->_status = SyncFileItem::FatalError; status = _item->_status = SyncFileItem::FatalError;
_item->_errorString = tr("Error writing metadata to the database"); _item->_errorString = tr("Error writing metadata to the database");

View file

@ -326,15 +326,16 @@ void OCC::SyncEngine::slotItemDiscovered(const OCC::SyncFileItemPtr &item)
const bool isReadOnly = !item->_remotePerm.isNull() && !item->_remotePerm.hasPermission(RemotePermissions::CanWrite); const bool isReadOnly = !item->_remotePerm.isNull() && !item->_remotePerm.hasPermission(RemotePermissions::CanWrite);
FileSystem::setFileReadOnlyWeak(filePath, isReadOnly); FileSystem::setFileReadOnlyWeak(filePath, isReadOnly);
} }
auto rec = item->toSyncJournalFileRecordWithInode(filePath);
_journal->setFileRecordMetadata(item->toSyncJournalFileRecordWithInode(filePath)); if (rec._checksumHeader.isEmpty())
rec._checksumHeader = prev._checksumHeader;
rec._serverHasIgnoredFiles |= prev._serverHasIgnoredFiles;
_journal->setFileRecord(rec);
// This might have changed the shared flag, so we must notify SyncFileStatusTracker for example // This might have changed the shared flag, so we must notify SyncFileStatusTracker for example
emit itemCompleted(item); emit itemCompleted(item);
} else { } else {
// The local tree is walked first and doesn't have all the info from the server.
// Update only outdated data from the disk. // Update only outdated data from the disk.
// FIXME! I think this is no longer the case so a setFileRecordMetadata should work
_journal->updateLocalMetadata(item->_file, item->_modtime, item->_size, item->_inode); _journal->updateLocalMetadata(item->_file, item->_modtime, item->_size, item->_inode);
} }
_hasNoneFiles = true; _hasNoneFiles = true;

View file

@ -81,7 +81,7 @@ private slots:
record._fileId = "efg"; record._fileId = "efg";
record._remotePerm = RemotePermissions::fromDbValue("NV"); record._remotePerm = RemotePermissions::fromDbValue("NV");
record._fileSize = 289055; record._fileSize = 289055;
_db.setFileRecordMetadata(record); _db.setFileRecord(record);
QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord)); QVERIFY(_db.getFileRecord(QByteArrayLiteral("foo"), &storedRecord));
QVERIFY(storedRecord == record); QVERIFY(storedRecord == record);