[traffic] Properly process message replacement

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-10-12 16:39:39 +03:00
parent d098ecae15
commit 2ed9bc1880
2 changed files with 38 additions and 17 deletions

View File

@@ -639,6 +639,13 @@ void TrafficManager::DecodeFirstMessage()
// store message in cache // store message in cache
m_messageCache.insert_or_assign(message.m_id, message); m_messageCache.insert_or_assign(message.m_id, message);
for (auto & replaced : message.m_replaces)
{
auto it = m_messageCache.find(replaced);
if (it != m_messageCache.cend())
m_messageCache.erase(it);
}
} }
/* /*
* TODO detect if we can do a quick update: * TODO detect if we can do a quick update:

View File

@@ -210,29 +210,43 @@ void TraffDecoder::DecodeMessage(traffxml::TraffMessage & message)
return; return;
traffxml::MultiMwmColoring decoded; traffxml::MultiMwmColoring decoded;
bool isDecoded = false;
auto it = m_messageCache.find(message.m_id); std::vector<std::string> ids = message.m_replaces;
if ((it != m_messageCache.end()) ids.insert(ids.begin(), message.m_id);
&& !it->second.m_decoded.empty()
&& (it->second.m_location == message.m_location)) for (auto & id : ids)
{ {
// cache already has a message with reusable location auto it = m_messageCache.find(id);
if ((it != m_messageCache.end())
LOG(LINFO, (" Location for message", message.m_id, "can be reused from cache")); && !it->second.m_decoded.empty()
&& (it->second.m_location == message.m_location))
std::optional<traffxml::TrafficImpact> cachedImpact = it->second.GetTrafficImpact();
if (cachedImpact.has_value() && cachedImpact.value() == impact.value())
{ {
LOG(LINFO, (" Impact for message", message.m_id, "unchanged, reusing cached coloring")); // cache already has a message with reusable location
// same impact, m_decoded can be reused altogether LOG(LINFO, (" Location for message", message.m_id, "can be reused from cache"));
message.m_decoded = it->second.m_decoded;
return; std::optional<traffxml::TrafficImpact> cachedImpact = it->second.GetTrafficImpact();
if (cachedImpact.has_value() && cachedImpact.value() == impact.value())
{
LOG(LINFO, (" Impact for message", message.m_id, "unchanged, reusing cached coloring"));
// same impact, m_decoded can be reused altogether
message.m_decoded = it->second.m_decoded;
return;
}
else if (!isDecoded)
{
/*
* populate only on first occurrence but continue searching, we might find a matching
* location with matching impact
*/
decoded = it->second.m_decoded;
isDecoded = true;
}
} }
else
decoded = it->second.m_decoded;
} }
else if (!isDecoded)
DecodeLocation(message, decoded); DecodeLocation(message, decoded);
if (impact) if (impact)