Initial moving of product listing to the background for level 3

This commit is contained in:
Dan Paulat 2025-08-30 16:27:55 -05:00
parent 68f66c0c2f
commit f4226b487d
14 changed files with 356 additions and 178 deletions

View file

@ -46,7 +46,9 @@ public:
std::string FindLatestKey() override;
std::chrono::system_clock::time_point FindLatestTime() override;
std::vector<std::chrono::system_clock::time_point>
GetTimePointsByDate(std::chrono::system_clock::time_point date) override;
GetTimePointsByDate(std::chrono::system_clock::time_point date,
bool update) override;
bool IsDateCached(std::chrono::system_clock::time_point date) override;
std::tuple<bool, size_t, size_t>
ListObjects(std::chrono::system_clock::time_point date) override;
std::shared_ptr<wsr88d::NexradFile>

View file

@ -2,17 +2,12 @@
#include <scwx/provider/nexrad_data_provider.hpp>
namespace Aws
{
namespace S3
namespace Aws::S3
{
class S3Client;
} // namespace S3
} // namespace Aws
} // namespace Aws::S3
namespace scwx
{
namespace provider
namespace scwx::provider
{
/**
@ -32,20 +27,23 @@ public:
AwsNexradDataProvider(AwsNexradDataProvider&&) noexcept;
AwsNexradDataProvider& operator=(AwsNexradDataProvider&&) noexcept;
size_t cache_size() const override;
[[nodiscard]] std::size_t cache_size() const override;
std::chrono::system_clock::time_point last_modified() const override;
std::chrono::seconds update_period() const override;
[[nodiscard]] std::chrono::system_clock::time_point
last_modified() const override;
[[nodiscard]] std::chrono::seconds update_period() const override;
std::string FindKey(std::chrono::system_clock::time_point time) override;
std::string FindLatestKey() override;
std::chrono::system_clock::time_point FindLatestTime() override;
std::vector<std::chrono::system_clock::time_point>
GetTimePointsByDate(std::chrono::system_clock::time_point date) override;
GetTimePointsByDate(std::chrono::system_clock::time_point date,
bool update) override;
bool IsDateCached(std::chrono::system_clock::time_point date) override;
std::tuple<bool, size_t, size_t>
ListObjects(std::chrono::system_clock::time_point date) override;
std::shared_ptr<wsr88d::NexradFile>
LoadObjectByKey(const std::string& key) override;
LoadObjectByKey(const std::string& key) override;
std::shared_ptr<wsr88d::NexradFile>
LoadObjectByTime(std::chrono::system_clock::time_point time) override;
std::pair<size_t, size_t> Refresh() override;
@ -61,5 +59,4 @@ private:
std::unique_ptr<Impl> p;
};
} // namespace provider
} // namespace scwx
} // namespace scwx::provider

View file

@ -7,9 +7,7 @@
#include <string>
#include <vector>
namespace scwx
{
namespace provider
namespace scwx::provider
{
class NexradDataProvider
@ -24,7 +22,7 @@ public:
NexradDataProvider(NexradDataProvider&&) noexcept;
NexradDataProvider& operator=(NexradDataProvider&&) noexcept;
virtual size_t cache_size() const = 0;
[[nodiscard]] virtual size_t cache_size() const = 0;
/**
* Gets the last modified time. This is equal to the most recent object's
@ -32,7 +30,8 @@ public:
*
* @return Last modified time
*/
virtual std::chrono::system_clock::time_point last_modified() const = 0;
[[nodiscard]] virtual std::chrono::system_clock::time_point
last_modified() const = 0;
/**
* Gets the current update period. This is equal to the difference between
@ -41,7 +40,7 @@ public:
*
* @return Update period
*/
virtual std::chrono::seconds update_period() const = 0;
[[nodiscard]] virtual std::chrono::seconds update_period() const = 0;
/**
* Finds the most recent key in the cache, no later than the time provided.
@ -116,7 +115,7 @@ public:
*
* @return NEXRAD data time point
*/
virtual std::chrono::system_clock::time_point
[[nodiscard]] virtual std::chrono::system_clock::time_point
GetTimePointByKey(const std::string& key) const = 0;
/**
@ -124,11 +123,22 @@ public:
* to the cache if required.
*
* @param date Date for which to get NEXRAD data time points
* @param update Whether or not to list and add data not present in the cache
*
* @return NEXRAD data time points
*/
virtual std::vector<std::chrono::system_clock::time_point>
GetTimePointsByDate(std::chrono::system_clock::time_point date) = 0;
GetTimePointsByDate(std::chrono::system_clock::time_point date,
bool update) = 0;
/**
* Determines if time points for the requested date are cached.
*
* @param date Date for which to query the cache
*
* @return Whether or not the requested date is cached
*/
virtual bool IsDateCached(std::chrono::system_clock::time_point date) = 0;
/**
* Requests available NEXRAD products for the current radar site, and adds
@ -148,5 +158,4 @@ private:
std::unique_ptr<Impl> p;
};
} // namespace provider
} // namespace scwx
} // namespace scwx::provider

View file

@ -289,11 +289,18 @@ AwsLevel2ChunksDataProvider::FindLatestTime()
std::vector<std::chrono::system_clock::time_point>
AwsLevel2ChunksDataProvider::GetTimePointsByDate(
std::chrono::system_clock::time_point /*date*/)
std::chrono::system_clock::time_point /* date */, bool /* update */)
{
return {};
}
bool AwsLevel2ChunksDataProvider::IsDateCached(
std::chrono::system_clock::time_point /* date */)
{
// No cache, default to true
return true;
}
std::chrono::system_clock::time_point
AwsLevel2ChunksDataProvider::Impl::GetScanTime(const std::string& prefix)
{

View file

@ -15,9 +15,7 @@
#include <aws/s3/model/ListObjectsV2Request.h>
#include <fmt/chrono.h>
namespace scwx
{
namespace provider
namespace scwx::provider
{
static const std::string logPrefix_ =
@ -177,7 +175,7 @@ std::chrono::system_clock::time_point AwsNexradDataProvider::FindLatestTime()
std::vector<std::chrono::system_clock::time_point>
AwsNexradDataProvider::GetTimePointsByDate(
std::chrono::system_clock::time_point date)
std::chrono::system_clock::time_point date, bool update)
{
const auto day = std::chrono::floor<std::chrono::days>(date);
@ -188,23 +186,26 @@ AwsNexradDataProvider::GetTimePointsByDate(
std::shared_lock lock(p->objectsMutex_);
// Is the date present in the date list?
bool currentDatePresent;
bool currentDatePresent = false;
auto currentDateIterator =
std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day);
if (currentDateIterator == p->objectDates_.cend())
{
// Temporarily unlock mutex
lock.unlock();
// List objects, since the date is not present in the date list
auto [success, newObjects, totalObjects] = ListObjects(date);
if (success)
if (update)
{
p->UpdateObjectDates(date);
}
// Temporarily unlock mutex
lock.unlock();
// Re-lock mutex
lock.lock();
// List objects, since the date is not present in the date list
const auto [success, newObjects, totalObjects] = ListObjects(date);
if (success)
{
p->UpdateObjectDates(date);
}
// Re-lock mutex
lock.lock();
}
currentDatePresent = false;
}
@ -214,8 +215,8 @@ AwsNexradDataProvider::GetTimePointsByDate(
}
// Determine objects to retrieve
auto objectsBegin = p->objects_.lower_bound(day);
auto objectsEnd = p->objects_.lower_bound(day + std::chrono::days {1});
const auto objectsBegin = p->objects_.lower_bound(day);
const auto objectsEnd = p->objects_.lower_bound(day + std::chrono::days {1});
// Copy time points to destination vector
std::transform(objectsBegin,
@ -236,6 +237,20 @@ AwsNexradDataProvider::GetTimePointsByDate(
return timePoints;
}
bool AwsNexradDataProvider::IsDateCached(
std::chrono::system_clock::time_point date)
{
const auto day = std::chrono::floor<std::chrono::days>(date);
const std::shared_lock lock(p->objectsMutex_);
// Is the date present in the date list?
const auto currentDateIterator =
std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day);
return currentDateIterator != p->objectDates_.cend();
}
std::tuple<bool, size_t, size_t>
AwsNexradDataProvider::ListObjects(std::chrono::system_clock::time_point date)
{
@ -446,5 +461,4 @@ void AwsNexradDataProvider::Impl::UpdateObjectDates(
objectDates_.push_back(day);
}
} // namespace provider
} // namespace scwx
} // namespace scwx::provider