refs #852 CAirspaceMonitor has no maximum number of parts per callsign,

but regularly prune the list based on timestamp age.
This commit is contained in:
Mathew Sutcliffe
2017-01-09 02:32:24 +00:00
parent bc38a0cea1
commit 76cc9f8ad8
2 changed files with 7 additions and 2 deletions

View File

@@ -1238,7 +1238,12 @@ namespace BlackCore
// list sorted from new to old
QWriteLocker lock(&m_lockParts);
CAircraftPartsList &partsList = this->m_partsByCallsign[callsign];
partsList.push_frontMaxElements(parts, MaxPartsPerCallsign);
partsList.push_front(parts);
// remove outdated parts (but never remove the most recent one)
const auto predicate = [now = parts.getMSecsSinceEpoch()](const auto & p) { return p.getMSecsSinceEpoch() >= now - PartsPerCallsignMaxAgeInSeconds * 1000; };
const auto newEnd = std::find_if(partsList.rbegin(), partsList.rend(), predicate).base();
partsList.erase(newEnd, partsList.end());
partsList.front().setTimeOffsetMs(timeOffsetMs);

View File

@@ -48,7 +48,7 @@ namespace BlackMisc
{
public:
static constexpr int MaxSituationsPerCallsign = 6; //!< How many situations per callsign
static constexpr int MaxPartsPerCallsign = 3; //!< How many parts per callsign
static constexpr int PartsPerCallsignMaxAgeInSeconds = 20; //!< How many seconds to keep parts for
//! Situations per callsign
using CSituationsPerCallsign = QHash<BlackMisc::Aviation::CCallsign, BlackMisc::Aviation::CAircraftSituationList>;