From be3792b93ae3f6a7b13d6ae06769a0e5148b37db Mon Sep 17 00:00:00 2001 From: mvglasow Date: Tue, 22 Jul 2025 22:55:59 +0300 Subject: [PATCH] [traffic] Remove obsolete code Signed-off-by: mvglasow --- traffic/traffic_info.cpp | 201 --------------------------------------- traffic/traffic_info.hpp | 44 --------- 2 files changed, 245 deletions(-) diff --git a/traffic/traffic_info.cpp b/traffic/traffic_info.cpp index b7b646898..0cda53799 100644 --- a/traffic/traffic_info.cpp +++ b/traffic/traffic_info.cpp @@ -61,22 +61,6 @@ bool ReadRemoteFile(string const & url, vector & contents, int & errorC return true; } -// TODO no longer needed -#ifdef traffic_dead_code -string MakeRemoteURL(string const & name, uint64_t version) -{ - if (string(TRAFFIC_DATA_BASE_URL).empty()) - return {}; - - stringstream ss; - ss << TRAFFIC_DATA_BASE_URL; - if (version != 0) - ss << version << "/"; - ss << url::UrlEncode(name) << TRAFFIC_FILE_EXTENSION; - return ss.str(); -} -#endif - char const kETag[] = "etag"; } // namespace @@ -94,51 +78,6 @@ TrafficInfo::RoadSegmentId::RoadSegmentId(uint32_t fid, uint16_t idx, uint8_t di uint8_t const TrafficInfo::kLatestKeysVersion = 0; uint8_t const TrafficInfo::kLatestValuesVersion = 0; -// TODO no longer needed -#ifdef traffic_dead_code -TrafficInfo::TrafficInfo(MwmSet::MwmId const & mwmId, int64_t currentDataVersion) - : m_mwmId(mwmId) - , m_currentDataVersion(currentDataVersion) -{ - if (!mwmId.IsAlive()) - { - LOG(LWARNING, ("Attempt to create a traffic info for dead mwm.")); - return; - } - string const mwmPath = mwmId.GetInfo()->GetLocalFile().GetPath(MapFileType::Map); - try - { - FilesContainerR rcont(mwmPath); - if (rcont.IsExist(TRAFFIC_KEYS_FILE_TAG)) - { - auto reader = rcont.GetReader(TRAFFIC_KEYS_FILE_TAG); - vector buf(static_cast(reader.Size())); - reader.Read(0, buf.data(), buf.size()); - LOG(LINFO, ("Reading keys for", mwmId, "from section")); - try - { - DeserializeTrafficKeys(buf, m_keys); - } - catch (Reader::Exception const & e) - { - auto const info = mwmId.GetInfo(); - LOG(LINFO, ("Could not read traffic keys from section. MWM:", info->GetCountryName(), - "Version:", info->GetVersion())); - } - } - else - { - LOG(LINFO, ("Reading traffic keys for", mwmId, "from the web")); - ReceiveTrafficKeys(); - } - } - catch (RootException const & e) - { - LOG(LWARNING, ("Could not initialize traffic keys")); - } -} -#endif - TrafficInfo::TrafficInfo(MwmSet::MwmId const & mwmId, Coloring && coloring) : m_mwmId(mwmId) , m_coloring(std::move(coloring)) @@ -160,25 +99,6 @@ void TrafficInfo::SetTrafficKeysForTesting(vector const & keys) m_availability = Availability::IsAvailable; } -// TODO no longer needed -#ifdef traffic_dead_code -bool TrafficInfo::ReceiveTrafficData(string & etag) -{ - vector values; - switch (ReceiveTrafficValues(etag, values)) - { - case ServerDataStatus::New: - return UpdateTrafficData(values); - case ServerDataStatus::NotChanged: - return true; - case ServerDataStatus::NotFound: - case ServerDataStatus::Error: - return false; - } - return false; -} -#endif - SpeedGroup TrafficInfo::GetSpeedGroup(RoadSegmentId const & id) const { auto const it = m_coloring.find(id); @@ -408,95 +328,6 @@ void TrafficInfo::DeserializeTrafficValues(vector const & data, ASSERT_EQUAL(src.Size(), 0, ()); } -// TODO no longer needed -#ifdef traffic_dead_code -// todo(@m) This is a temporary method. Do not refactor it. -bool TrafficInfo::ReceiveTrafficKeys() -{ - if (!m_mwmId.IsAlive()) - return false; - auto const & info = m_mwmId.GetInfo(); - if (!info) - return false; - - string const url = MakeRemoteURL(info->GetCountryName(), info->GetVersion()); - - if (url.empty()) - return false; - - vector contents; - int errorCode; - if (!ReadRemoteFile(url + ".keys", contents, errorCode)) - return false; - if (errorCode != 200) - { - LOG(LWARNING, ("Network error when reading keys")); - return false; - } - - vector keys; - try - { - DeserializeTrafficKeys(contents, keys); - } - catch (Reader::Exception const & e) - { - LOG(LINFO, ("Could not read traffic keys received from server. MWM:", info->GetCountryName(), - "Version:", info->GetVersion())); - return false; - } - m_keys.swap(keys); - return true; -} -#endif - -// TODO no longer needed -#ifdef traffic_dead_code -TrafficInfo::ServerDataStatus TrafficInfo::ReceiveTrafficValues(string & etag, vector & values) -{ - if (!m_mwmId.IsAlive()) - return ServerDataStatus::Error; - - auto const & info = m_mwmId.GetInfo(); - if (!info) - return ServerDataStatus::Error; - - auto const version = info->GetVersion(); - string const url = MakeRemoteURL(info->GetCountryName(), version); - - if (url.empty()) - return ServerDataStatus::Error; - - platform::HttpClient request(url); - request.LoadHeaders(true); - request.SetRawHeader("If-None-Match", etag); - - if (!request.RunHttpRequest() || request.ErrorCode() != 200) - return ProcessFailure(request, version); - try - { - string const & response = request.ServerResponse(); - vector contents(response.cbegin(), response.cend()); - DeserializeTrafficValues(contents, values); - } - catch (Reader::Exception const & e) - { - m_availability = Availability::NoData; - LOG(LWARNING, ("Could not read traffic values received from server. MWM:", - info->GetCountryName(), "Version:", info->GetVersion())); - return ServerDataStatus::Error; - } - // Update ETag for this MWM. - auto const & headers = request.GetHeaders(); - auto const it = headers.find(kETag); - if (it != headers.end()) - etag = it->second; - - m_availability = Availability::IsAvailable; - return ServerDataStatus::New; -} -#endif - bool TrafficInfo::UpdateTrafficData(vector const & values) { m_coloring.clear(); @@ -519,38 +350,6 @@ bool TrafficInfo::UpdateTrafficData(vector const & values) return true; } -// TODO no longer needed -#ifdef traffic_dead_code -TrafficInfo::ServerDataStatus TrafficInfo::ProcessFailure(platform::HttpClient const & request, int64_t const mwmVersion) -{ - switch (request.ErrorCode()) - { - case 404: /* Not Found */ - { - int64_t version = 0; - VERIFY(strings::to_int64(request.ServerResponse().c_str(), version), ()); - - if (version > mwmVersion && version <= m_currentDataVersion) - m_availability = Availability::ExpiredData; - else if (version > m_currentDataVersion) - m_availability = Availability::ExpiredApp; - else - m_availability = Availability::NoData; - return ServerDataStatus::NotFound; - } - case 304: /* Not Modified */ - { - m_availability = Availability::IsAvailable; - return ServerDataStatus::NotChanged; - } - } - - m_availability = Availability::Unknown; - - return ServerDataStatus::Error; -} -#endif - string DebugPrint(TrafficInfo::RoadSegmentId const & id) { string const dir = diff --git a/traffic/traffic_info.hpp b/traffic/traffic_info.hpp index 61a4e3474..d7fe391f7 100644 --- a/traffic/traffic_info.hpp +++ b/traffic/traffic_info.hpp @@ -105,11 +105,6 @@ public: TrafficInfo() = default; -// TODO no longer needed -#ifdef traffic_dead_code - TrafficInfo(MwmSet::MwmId const & mwmId, int64_t currentDataVersion); -#endif - TrafficInfo(MwmSet::MwmId const & mwmId, Coloring && coloring); /** @@ -120,25 +115,6 @@ public: static TrafficInfo BuildForTesting(Coloring && coloring); void SetTrafficKeysForTesting(std::vector const & keys); -// TODO no longer needed -#ifdef traffic_dead_code - /** - * @brief Fetches the latest traffic data from the server and updates the coloring and ETag. - * - * The url is constructed using the `mwmId` specified in the constructor. - * - * The ETag or entity tag is part of HTTP, the protocol for the World Wide Web. - * It is one of several mechanisms that HTTP provides for web cache validation, - * which allows a client to make conditional requests. - * - * NOTE: This method must not be called on the UI thread. - * - * @param etag The entity tag - * @return True on success, false on failure. - */ - bool ReceiveTrafficData(std::string & etag); -#endif - /** * @brief Returns the latest known speed group by a feature segment's ID. * @param id The road segment ID. @@ -205,29 +181,9 @@ private: friend void UnitTest_TrafficInfo_UpdateTrafficData(); -// TODO no longer needed -#ifdef traffic_dead_code - // todo(@m) A temporary method. Remove it once the keys are added - // to the generator and the data is regenerated. - bool ReceiveTrafficKeys(); -#endif - -// TODO no longer needed -#ifdef traffic_dead_code - // Tries to read the values of the Coloring map from server into |values|. - // Returns result of communicating with server as ServerDataStatus. - // Otherwise, returns false and does not change m_coloring. - ServerDataStatus ReceiveTrafficValues(std::string & etag, std::vector & values); -#endif - // Updates the coloring and changes the availability status if needed. bool UpdateTrafficData(std::vector const & values); -// TODO no longer needed -#ifdef traffic_dead_code - ServerDataStatus ProcessFailure(platform::HttpClient const & request, int64_t const mwmVersion); -#endif - /** * @brief The mapping from feature segments to speed groups (see speed_groups.hpp). */