Make archive event pruning more robust

This commit is contained in:
Dan Paulat 2025-05-05 00:25:28 -05:00
parent 0c59a0d4d2
commit 490989ac2a

View file

@ -570,9 +570,10 @@ void TextEventManager::Impl::PruneArchives()
const std::unique_lock archiveEventKeyLock {archiveEventKeyMutex_};
// If there are the same number of dates in both archiveEventKeys_ and
// archiveDates_, there is nothing to prune
if (archiveEventKeys_.size() == archiveDates_.size())
// If there are the same number of dates in archiveEventKeys_, archiveDates_
// and unloadedProductMap_, there is nothing to prune
if (archiveEventKeys_.size() == archiveDates_.size() &&
unloadedProductMap_.size() == archiveDates_.size())
{
// Nothing to prune
return;
@ -594,7 +595,6 @@ void TextEventManager::Impl::PruneArchives()
// The date is not in the list of recent dates, remove it
it = archiveEventKeys_.erase(it);
unloadedProductMap_.erase(date);
}
else
{
@ -606,6 +606,24 @@ void TextEventManager::Impl::PruneArchives()
}
}
for (auto it = unloadedProductMap_.begin(); it != unloadedProductMap_.end();)
{
const auto& date = it->first;
// If date is not in recent days map
if (std::find(archiveDates_.cbegin(), archiveDates_.cend(), date) ==
archiveDates_.cend())
{
// The date is not in the list of recent dates, remove it
it = unloadedProductMap_.erase(it);
}
else
{
// The date is recent, keep it
++it;
}
}
// Remove elements from eventKeysToPrune if they are in eventKeysToKeep
for (const auto& eventKey : eventKeysToKeep)
{