forked from organicmaps/organicmaps
[alohalytics] Fixed weird bug when force_upload was uninitialized and randomly set to true in Release builds so some events were lost and many small events were sent to a server.
This commit is contained in:
parent
444e26171f
commit
24b8267396
2 changed files with 13 additions and 9 deletions
|
@ -38,11 +38,15 @@ namespace alohalytics {
|
|||
|
||||
typedef std::map<std::string, std::string> TStringMap;
|
||||
|
||||
struct MQMessage {
|
||||
std::string message;
|
||||
MQMessage(std::string&& msg) : message(msg) {}
|
||||
bool force_upload;
|
||||
explicit MQMessage(bool force_upload = false) : force_upload(force_upload) {}
|
||||
class MQMessage {
|
||||
std::string message_;
|
||||
bool force_upload_;
|
||||
public:
|
||||
MQMessage(std::string&& msg) : message_(msg), force_upload_(false) {}
|
||||
explicit MQMessage(bool force_upload = false) : force_upload_(force_upload) {}
|
||||
// True for special empty message which should force stats uploading.
|
||||
bool ForceUpload() const { return force_upload_; }
|
||||
std::string const & GetMessage() const { return message_; }
|
||||
};
|
||||
|
||||
class Stats final {
|
||||
|
|
|
@ -77,10 +77,10 @@ bool Stats::UploadBuffer(const std::string& url, std::string&& buffer, bool debu
|
|||
// TODO(AlexZ): Refactor message queue to make this method private.
|
||||
void Stats::OnMessage(const MQMessage& message, size_t dropped_events) {
|
||||
if (dropped_events) {
|
||||
LOG_IF_DEBUG("Warning:", dropped_events, "were dropped from the queue.");
|
||||
LOG_IF_DEBUG("Warning:", dropped_events, "events were dropped from the queue.");
|
||||
}
|
||||
|
||||
if (message.force_upload) {
|
||||
if (message.ForceUpload()) {
|
||||
if (upload_url_.empty()) {
|
||||
LOG_IF_DEBUG("Warning: Can't upload in-memory events because upload url has not been set.");
|
||||
return;
|
||||
|
@ -106,10 +106,10 @@ void Stats::OnMessage(const MQMessage& message, size_t dropped_events) {
|
|||
}
|
||||
} else {
|
||||
if (file_storage_queue_) {
|
||||
file_storage_queue_->PushMessage(message.message);
|
||||
file_storage_queue_->PushMessage(message.GetMessage());
|
||||
} else {
|
||||
auto& container = memory_storage_;
|
||||
container.push_back(message.message);
|
||||
container.push_back(message.GetMessage());
|
||||
constexpr size_t kMaxEventsInMemory = 2048;
|
||||
if (container.size() > kMaxEventsInMemory) {
|
||||
container.pop_front();
|
||||
|
|
Loading…
Add table
Reference in a new issue