feat: add ability to limit message snapshot size (#6602)
Reviewed-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -324,6 +324,18 @@ public:
|
||||
return LimitedQueueSnapshot<T>(this->buffer_);
|
||||
}
|
||||
|
||||
[[nodiscard]] LimitedQueueSnapshot<T> lastN(size_t nItems) const
|
||||
{
|
||||
std::shared_lock lock(this->mutex_);
|
||||
return LimitedQueueSnapshot<T>::lastN(this->buffer_, nItems);
|
||||
}
|
||||
|
||||
[[nodiscard]] LimitedQueueSnapshot<T> firstN(size_t nItems) const
|
||||
{
|
||||
std::shared_lock lock(this->mutex_);
|
||||
return LimitedQueueSnapshot<T>::firstN(this->buffer_, nItems);
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,24 @@ private:
|
||||
{
|
||||
}
|
||||
|
||||
static LimitedQueueSnapshot lastN(const boost::circular_buffer<T> &buf,
|
||||
size_t n)
|
||||
{
|
||||
return {buf.end() - std::min(n, buf.size()), buf.end()};
|
||||
}
|
||||
|
||||
static LimitedQueueSnapshot firstN(const boost::circular_buffer<T> &buf,
|
||||
size_t n)
|
||||
{
|
||||
return {buf.begin(), buf.begin() + std::min(n, buf.size())};
|
||||
}
|
||||
|
||||
template <typename It>
|
||||
LimitedQueueSnapshot(It begin, It end)
|
||||
: buffer_(std::move(begin), std::move(end))
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
LimitedQueueSnapshot() = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user