Synchronously load file in FileManager::add_file_source to avoid resaving it to the database.

This commit is contained in:
levlam 2022-10-06 13:48:52 +03:00
parent 6176272d60
commit 1e6a6c28af
3 changed files with 7 additions and 7 deletions

View File

@ -53,7 +53,7 @@ inline StringBuilder &operator<<(StringBuilder &sb, const FileData &file_data) {
if (file_data.remote_.type() == RemoteFileLocation::Type::Full) {
sb << " remote " << file_data.remote_.full();
}
sb << format::as_array(file_data.file_source_ids_);
sb << ", sources = " << format::as_array(file_data.file_source_ids_);
return sb << "]";
}

View File

@ -68,9 +68,9 @@ class FileDbInterface {
Result<FileData> get_file_data_sync(const LocationT &location) {
auto res = get_file_data_sync_impl(as_key(location));
if (res.is_ok()) {
LOG(DEBUG) << "GET " << location << " " << res.ok();
LOG(DEBUG) << "GET " << location << ": " << res.ok();
} else {
LOG(DEBUG) << "GET " << location << " " << res.error();
LOG(DEBUG) << "GET " << location << ": " << res.error();
}
return res;
}

View File

@ -1742,7 +1742,7 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
}
void FileManager::add_file_source(FileId file_id, FileSourceId file_source_id) {
auto node = get_file_node(file_id);
auto node = get_sync_file_node(file_id); // synchronously load the file to preload known file sources
if (!node) {
return;
}
@ -1755,7 +1755,7 @@ void FileManager::add_file_source(FileId file_id, FileSourceId file_source_id) {
}
void FileManager::remove_file_source(FileId file_id, FileSourceId file_source_id) {
auto node = get_file_node(file_id);
auto node = get_sync_file_node(file_id); // synchronously load the file to preload known file sources
if (!node) {
return;
}
@ -1992,8 +1992,8 @@ void FileManager::load_from_pmc(FileNodePtr node, bool new_remote, bool new_loca
generate = file_view.generate_location();
}
LOG(DEBUG) << "Load from pmc " << file_id << "/" << file_view.get_main_file_id() << ", new_remote = " << new_remote
<< ", new_local = " << new_local << ", new_generate = " << new_generate;
LOG(DEBUG) << "Load from pmc file " << file_id << '/' << file_view.get_main_file_id()
<< ", new_remote = " << new_remote << ", new_local = " << new_local << ", new_generate = " << new_generate;
auto load = [&](auto location) {
TRY_RESULT(file_data, file_db_->get_file_data_sync(location));
TRY_RESULT(new_file_id,