From 490989ac2ad5345eb46ec63e14279ca5b508f31d Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 5 May 2025 00:25:28 -0500 Subject: [PATCH] Make archive event pruning more robust --- .../scwx/qt/manager/text_event_manager.cpp | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp index 70505d44..8aa4c611 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -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) {