diff --git a/map/framework.cpp b/map/framework.cpp index 5e72dd6139..ea56f94e96 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -3313,11 +3313,12 @@ void Framework::UploadUGC(User::CompleteUploadingHandler const & onCompleteUploa return; } - m_ugcApi->GetUGCToSend([this, onCompleteUploading](string && json) + m_ugcApi->GetUGCToSend([this, onCompleteUploading](string && json, size_t numberOfUnsynchronized) { if (!json.empty()) { - m_user.UploadUserReviews(std::move(json), [this, onCompleteUploading](bool isSuccessful) + m_user.UploadUserReviews(std::move(json), numberOfUnsynchronized, + [this, onCompleteUploading](bool isSuccessful) { if (onCompleteUploading != nullptr) onCompleteUploading(isSuccessful); diff --git a/map/user.cpp b/map/user.cpp index 7db4a25a39..a269c01f58 100644 --- a/map/user.cpp +++ b/map/user.cpp @@ -313,7 +313,7 @@ void User::RequestUserDetails() }); } -void User::UploadUserReviews(std::string && dataStr, +void User::UploadUserReviews(std::string && dataStr, size_t numberOfUnsynchronized, CompleteUploadingHandler const & onCompleteUploading) { std::string const url = ReviewReceiverUrl(); @@ -326,7 +326,8 @@ void User::UploadUserReviews(std::string && dataStr, if (m_accessToken.empty()) return; - GetPlatform().RunTask(Platform::Thread::Network, [this, url, dataStr, onCompleteUploading]() + GetPlatform().RunTask(Platform::Thread::Network, + [this, url, dataStr, numberOfUnsynchronized, onCompleteUploading]() { size_t const bytesCount = dataStr.size(); Request(url, [this, dataStr](platform::HttpClient & request) @@ -343,10 +344,11 @@ void User::UploadUserReviews(std::string && dataStr, if (onCompleteUploading != nullptr) onCompleteUploading(true /* isSuccessful */); }, - [this, onCompleteUploading](int errorCode) + [this, onCompleteUploading, numberOfUnsynchronized](int errorCode) { alohalytics::Stats::Instance().LogEvent("UGC_DataUpload_error", - strings::to_string(errorCode)); + {{"error", strings::to_string(errorCode)}, + {"num", strings::to_string(numberOfUnsynchronized)}}); LOG(LWARNING, ("Reviews have not been uploaded. Code =", errorCode)); if (onCompleteUploading != nullptr) diff --git a/map/user.hpp b/map/user.hpp index 04639142f6..ab82b6bfc2 100644 --- a/map/user.hpp +++ b/map/user.hpp @@ -60,7 +60,7 @@ public: std::string GetAccessToken() const; Details GetDetails() const; - void UploadUserReviews(std::string && dataStr, + void UploadUserReviews(std::string && dataStr, size_t numberOfUnsynchronized, CompleteUploadingHandler const & onCompleteUploading); private: diff --git a/ugc/api.cpp b/ugc/api.cpp index 7fb2a40954..e11d07380b 100644 --- a/ugc/api.cpp +++ b/ugc/api.cpp @@ -73,7 +73,7 @@ void Api::GetUGCToSendImpl(UGCJsonToSendCallback const & callback) { CHECK(callback, ()); auto json = m_storage.GetUGCToSend(); - callback(move(json)); + callback(move(json), m_storage.GetNumberOfUnsynchronized()); } void Api::SendingCompletedImpl() diff --git a/ugc/api.hpp b/ugc/api.hpp index 6b08de71b6..60dd7a7e12 100644 --- a/ugc/api.hpp +++ b/ugc/api.hpp @@ -20,7 +20,7 @@ class Api public: using UGCCallback = platform::SafeCallback; using UGCCallbackUnsafe = std::function; - using UGCJsonToSendCallback = std::function; + using UGCJsonToSendCallback = std::function; using OnResultCallback = platform::SafeCallback; explicit Api(Index const & index); diff --git a/ugc/storage.cpp b/ugc/storage.cpp index 02f35eabd5..25289571c0 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -18,6 +18,7 @@ #include #include +#include "3party/Alohalytics/src/alohalytics.h" #include "3party/jansson/myjansson.hpp" namespace ugc @@ -203,11 +204,20 @@ void Storage::Load() return; } + size_t numberOfUnsynchronized = 0; DeserializeUGCIndex(data, m_UGCIndexes); for (auto const & i : m_UGCIndexes) { if (i.m_deleted) ++m_numberOfDeleted; + else if (!i.m_synchronized) + ++numberOfUnsynchronized; + } + + if (numberOfUnsynchronized > 1) + { + alohalytics::Stats::Instance().LogEvent("UGC_unsent", + {{"num", strings::to_string(numberOfUnsynchronized)}}); } } @@ -341,6 +351,17 @@ string Storage::GetUGCToSend() const return string(buffer.get()); } +size_t Storage::GetNumberOfUnsynchronized() const +{ + size_t numberOfUnsynchronized = 0; + for (auto const & i : m_UGCIndexes) + { + if (!i.m_deleted && !i.m_synchronized) + ++numberOfUnsynchronized; + } + return numberOfUnsynchronized; +} + void Storage::MarkAllAsSynchronized() { if (m_UGCIndexes.empty()) diff --git a/ugc/storage.hpp b/ugc/storage.hpp index 8eb4022fa6..26b538d1f2 100644 --- a/ugc/storage.hpp +++ b/ugc/storage.hpp @@ -56,6 +56,7 @@ public: void MarkAllAsSynchronized(); void Defragmentation(); void Load(); + size_t GetNumberOfUnsynchronized() const; /// Testing std::vector const & GetIndexesForTesting() const { return m_UGCIndexes; }