Added new UGC statistics

This commit is contained in:
r.kuznetsov 2018-02-19 11:12:04 +03:00 committed by Arsentiy Milchakov
parent 402f11a34a
commit 3b847eb6dc
7 changed files with 34 additions and 9 deletions

View file

@ -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);

View file

@ -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)

View file

@ -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:

View file

@ -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()

View file

@ -20,7 +20,7 @@ class Api
public:
using UGCCallback = platform::SafeCallback<void(UGC const & ugc, UGCUpdate const & update)>;
using UGCCallbackUnsafe = std::function<void(UGC const & ugc, UGCUpdate const & update)>;
using UGCJsonToSendCallback = std::function<void(std::string && jsonStr)>;
using UGCJsonToSendCallback = std::function<void(std::string && jsonStr, size_t numberOfUnsynchronized)>;
using OnResultCallback = platform::SafeCallback<void(Storage::SettingResult const result)>;
explicit Api(Index const & index);

View file

@ -18,6 +18,7 @@
#include <algorithm>
#include <utility>
#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())

View file

@ -56,6 +56,7 @@ public:
void MarkAllAsSynchronized();
void Defragmentation();
void Load();
size_t GetNumberOfUnsynchronized() const;
/// Testing
std::vector<UGCIndex> const & GetIndexesForTesting() const { return m_UGCIndexes; }