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 LocalAdsManager::GetRequestedCampaigns(std::vectorsecond.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 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 && 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 m_failedDownloads;