diff options
author | mpimenov <mpimenov@users.noreply.github.com> | 2016-11-23 15:18:03 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-23 15:18:03 +0300 |
commit | f14ded9bbdc8231d0f9833e37b4c6fc15f84574f (patch) | |
tree | dfe5e9a260574cb08edee523937a5863b57db9d3 | |
parent | 86b91df9ba621d35572ed7b6bbfe71f69c9c4261 (diff) | |
parent | 30e73437093449610cb2173166d3d37d85210769 (diff) |
Merge pull request #4786 from darina/last-seen-mwm-fix
Last seen mwm time fixed.
-rw-r--r-- | map/traffic_manager.cpp | 31 | ||||
-rw-r--r-- | map/traffic_manager.hpp | 8 |
2 files changed, 21 insertions, 18 deletions
diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index bd3ff9fdd9..cf5acfc085 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -48,7 +48,7 @@ void TrafficManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine) void TrafficManager::OnRecover() { - m_mwmInfos.clear(); + m_mwmCache.clear(); UpdateViewport(m_currentModelView); UpdateMyPosition(m_currentPosition); @@ -141,19 +141,22 @@ void TrafficManager::RequestTrafficData() ASSERT(mwmId.IsAlive(), ()); bool needRequesting = false; - auto it = m_mwmInfos.find(mwmId); - if (it == m_mwmInfos.end()) + auto currentTime = steady_clock::now(); + + auto it = m_mwmCache.find(mwmId); + if (it == m_mwmCache.end()) { needRequesting = true; - m_mwmInfos.insert(make_pair(mwmId, MwmTrafficInfo(steady_clock::now()))); + m_mwmCache.insert(make_pair(mwmId, CacheEntry(currentTime))); } else { - auto const passedSeconds = steady_clock::now() - it->second.m_lastRequestTime; + it->second.m_lastSeenTime = currentTime; + auto const passedSeconds = currentTime - it->second.m_lastRequestTime; if (passedSeconds >= kUpdateInterval) { needRequesting = true; - it->second.m_lastRequestTime = steady_clock::now(); + it->second.m_lastRequestTime = currentTime; } } @@ -170,8 +173,8 @@ void TrafficManager::RequestTrafficData(MwmSet::MwmId const & mwmId) void TrafficManager::OnTrafficDataResponse(traffic::TrafficInfo const & info) { - auto it = m_mwmInfos.find(info.GetMwmId()); - if (it == m_mwmInfos.end()) + auto it = m_mwmCache.find(info.GetMwmId()); + if (it == m_mwmCache.end()) return; // Update cache. @@ -190,24 +193,24 @@ void TrafficManager::OnTrafficDataResponse(traffic::TrafficInfo const & info) void TrafficManager::CheckCacheSize() { - if ((m_currentCacheSizeBytes > m_maxCacheSizeBytes) && (m_mwmInfos.size() > m_activeMwms.size())) + if (m_currentCacheSizeBytes > m_maxCacheSizeBytes && m_mwmCache.size() > m_activeMwms.size()) { std::multimap<time_point<steady_clock>, MwmSet::MwmId> seenTimings; - for (auto const & mwmInfo : m_mwmInfos) + for (auto const & mwmInfo : m_mwmCache) seenTimings.insert(make_pair(mwmInfo.second.m_lastSeenTime, mwmInfo.first)); auto itSeen = seenTimings.begin(); - while ((m_currentCacheSizeBytes > m_maxCacheSizeBytes) && - (m_mwmInfos.size() > m_activeMwms.size())) + while (m_currentCacheSizeBytes > m_maxCacheSizeBytes && + m_mwmCache.size() > m_activeMwms.size()) { auto const mwmId = itSeen->second; - auto const it = m_mwmInfos.find(mwmId); + auto const it = m_mwmCache.find(mwmId); if (it->second.m_isLoaded) { m_currentCacheSizeBytes -= it->second.m_dataSize; m_drapeEngine->ClearTrafficCache(mwmId); } - m_mwmInfos.erase(it); + m_mwmCache.erase(it); ++itSeen; } } diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index ae7838251c..c8ccc17ace 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -71,11 +71,11 @@ private: MyPosition m_currentPosition; ScreenBase m_currentModelView; - struct MwmTrafficInfo + struct CacheEntry { - MwmTrafficInfo() = default; + CacheEntry() = default; - MwmTrafficInfo(time_point<steady_clock> const & requestTime) : m_lastRequestTime(requestTime) {} + CacheEntry(time_point<steady_clock> const & requestTime) : m_lastRequestTime(requestTime) {} bool m_isLoaded = false; time_point<steady_clock> m_lastSeenTime; time_point<steady_clock> m_lastRequestTime; @@ -85,7 +85,7 @@ private: size_t m_maxCacheSizeBytes; size_t m_currentCacheSizeBytes; - map<MwmSet::MwmId, MwmTrafficInfo> m_mwmInfos; + map<MwmSet::MwmId, CacheEntry> m_mwmCache; bool m_isRunning; condition_variable m_condition; |