Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--local_ads/statistics.cpp2
-rw-r--r--map/local_ads_manager.cpp19
-rw-r--r--map/local_ads_manager.hpp6
3 files changed, 17 insertions, 10 deletions
diff --git a/local_ads/statistics.cpp b/local_ads/statistics.cpp
index 790343124a..e23952df38 100644
--- a/local_ads/statistics.cpp
+++ b/local_ads/statistics.cpp
@@ -367,7 +367,7 @@ void Statistics::SendToServer()
auto const connectionStatus = GetPlatform().ConnectionStatus();
if (connectionStatus == Platform::EConnectionType::CONNECTION_WIFI)
{
- for (auto it = m_metadataCache.begin(); it != m_metadataCache.end();)
+ for (auto it = m_metadataCache.begin(); it != m_metadataCache.end(); ++it)
{
auto metadataKey = it->first;
auto metadata = it->second;
diff --git a/map/local_ads_manager.cpp b/map/local_ads_manager.cpp
index 53b506c451..476ff9d35e 100644
--- a/map/local_ads_manager.cpp
+++ b/map/local_ads_manager.cpp
@@ -279,13 +279,8 @@ std::vector<std::string> LocalAdsManager::GetRequestedCampaigns(std::vector<MwmS
// Skip downloading request if maximum attempts count has reached or
// we are waiting for new attempt.
auto const failedDownloadsIt = m_failedDownloads.find(mwm);
- if (failedDownloadsIt != m_failedDownloads.cend() &&
- (failedDownloadsIt->second.m_attemptsCount >= kMaxDownloadingAttempts ||
- std::chrono::steady_clock::now() <= failedDownloadsIt->second.m_lastDownloading +
- failedDownloadsIt->second.m_currentTimeout))
- {
+ if (failedDownloadsIt != m_failedDownloads.cend() && !failedDownloadsIt->second.CanRetry())
continue;
- }
std::string const & mwmName = info->GetCountryName();
auto campaignIt = m_campaigns.find(mwmName);
@@ -332,18 +327,20 @@ bool LocalAdsManager::DownloadCampaign(MwmSet::MwmId const & mwmId, std::vector<
std::lock_guard<std::mutex> lock(m_campaignsMutex);
if (!success)
{
+ bool const isAbsent = request.ErrorCode() == 404;
auto const it = m_failedDownloads.find(mwmId);
if (it == m_failedDownloads.cend())
{
m_failedDownloads.insert(std::make_pair(mwmId, BackoffStats(std::chrono::steady_clock::now(),
kFailedDownloadingTimeout,
- 1 /* m_attemptsCount */)));
+ 1 /* m_attemptsCount */, isAbsent)));
}
else
{
// Here we increase timeout multiplying by 2.
it->second.m_currentTimeout = std::chrono::seconds(it->second.m_currentTimeout.count() * 2);
it->second.m_attemptsCount++;
+ it->second.m_fileIsAbsent = isAbsent;
}
return false;
}
@@ -367,7 +364,7 @@ void LocalAdsManager::ProcessRequests(std::set<Request> && requests)
if (!mwm.IsAlive())
continue;
- std::string const countryName = mwm.GetInfo()->GetCountryName();
+ std::string const & countryName = mwm.GetInfo()->GetCountryName();
if (type == RequestType::Download)
{
// Download campaign data from server.
@@ -540,3 +537,9 @@ std::string LocalAdsManager::GetCompanyUrl(FeatureID const & featureId) const
{
return MakeCampaignPageURL(featureId);
}
+
+bool LocalAdsManager::BackoffStats::CanRetry() const
+{
+ return !m_fileIsAbsent && m_attemptsCount < kMaxDownloadingAttempts &&
+ std::chrono::steady_clock::now() > (m_lastDownloading + m_currentTimeout);
+}
diff --git a/map/local_ads_manager.hpp b/map/local_ads_manager.hpp
index 46fcc40088..92f33b9cbd 100644
--- a/map/local_ads_manager.hpp
+++ b/map/local_ads_manager.hpp
@@ -113,15 +113,19 @@ private:
BackoffStats() = default;
BackoffStats(std::chrono::steady_clock::time_point lastDownloading,
std::chrono::seconds currentTimeout,
- uint8_t attemptsCount)
+ uint8_t attemptsCount, bool fileIsAbsent)
: m_lastDownloading(lastDownloading)
, m_currentTimeout(currentTimeout)
, m_attemptsCount(attemptsCount)
+ , m_fileIsAbsent(fileIsAbsent)
{}
std::chrono::steady_clock::time_point m_lastDownloading = {};
std::chrono::seconds m_currentTimeout = std::chrono::seconds(0);
uint8_t m_attemptsCount = 0;
+ bool m_fileIsAbsent = false;
+
+ bool CanRetry() const;
};
std::map<MwmSet::MwmId, BackoffStats> m_failedDownloads;