Update recent object dates when date is already cached

This commit is contained in:
Dan Paulat 2023-05-26 01:14:42 -05:00
parent 27ce694df8
commit ca88d60a5d

View file

@ -165,13 +165,14 @@ AwsNexradDataProvider::GetTimePointsByDate(
std::vector<std::chrono::system_clock::time_point> timePoints {};
logger_->debug("GetTimePointsByDate: {}", util::TimeString(date));
logger_->trace("GetTimePointsByDate: {}", util::TimeString(date));
std::shared_lock lock(p->objectsMutex_);
// Is the date present in the date list?
if (std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day) ==
p->objectDates_.cend())
auto currentDateIterator =
std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day);
if (currentDateIterator == p->objectDates_.cend())
{
// Temporarily unlock mutex
lock.unlock();
@ -197,6 +198,16 @@ AwsNexradDataProvider::GetTimePointsByDate(
std::back_inserter(timePoints),
[](const auto& object) { return object.first; });
// Unlock mutex, finished
lock.unlock();
// If we haven't updated the most recently queried dates yet, because the
// date was already cached, update
if (currentDateIterator != p->objectDates_.cend())
{
p->UpdateObjectDates(date);
}
return timePoints;
}