From 4714ac6bde923dc2eea924f0d3dc31228f5695ca Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 26 Jan 2016 11:19:24 +0300 Subject: [PATCH] [editor] Uploader works with a copy of edited features. --- indexer/osm_editor.cpp | 26 +++++++++++++++++++++++--- indexer/osm_editor.hpp | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index e58bff28f4..f3bd968e51 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -627,10 +627,14 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset // TODO(AlexZ): features access should be synchronized. auto const lambda = [this](string key, string secret, TChangesetTags tags, TFinishUploadCallback callBack) { + // This lambda was designed to start after app goes into background. But for cases when user is immediately + // coming back to the app we work with a copy, because 'for' loops below can take a significant amount of time. + auto features = m_features; + int uploadedFeaturesCount = 0, errorsCount = 0; // TODO(AlexZ): insert usefull changeset comments. ChangesetWrapper changeset({key, secret}, tags); - for (auto & id : m_features) + for (auto & id : features) { for (auto & index : id.second) { @@ -683,9 +687,8 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset fti.m_uploadError = ex.what(); ++errorsCount; } - // TODO(AlexZ): Synchronize save after edits. // Call Save every time we modify each feature's information. - Save(GetEditorFilePath()); + SaveUploadedInformation(fti); } } @@ -707,6 +710,23 @@ void Editor::UploadChanges(string const & key, string const & secret, TChangeset future = async(launch::async, lambda, key, secret, tags, callBack); } +void Editor::SaveUploadedInformation(FeatureTypeInfo const & fromUploader) +{ + // TODO(AlexZ): Correctly synchronize this call and Save() at the end. + FeatureID const & fid = fromUploader.m_feature.GetID(); + auto id = m_features.find(fid.m_mwmId); + if (id == m_features.end()) + return; // Rare case: feature was deleted at the time of changes uploading. + auto index = id->second.find(fid.m_index); + if (index == id->second.end()) + return; // Rare case: feature was deleted at the time of changes uploading. + auto & fti = index->second; + fti.m_uploadAttemptTimestamp = fromUploader.m_uploadAttemptTimestamp; + fti.m_uploadStatus = fromUploader.m_uploadStatus; + fti.m_uploadError = fromUploader.m_uploadError; + Save(GetEditorFilePath()); +} + void Editor::RemoveFeatureFromStorageIfExists(MwmSet::MwmId const & mwmId, uint32_t index) { auto matchedMwm = m_features.find(mwmId); diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index 3a5355d472..667bc3dc3e 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -129,6 +129,7 @@ private: string m_uploadStatus; string m_uploadError; }; + void SaveUploadedInformation(FeatureTypeInfo const & fromUploader); // TODO(AlexZ): Synchronize multithread access. /// Deleted, edited and created features.