Improve TQueue::clear.

This commit is contained in:
levlam 2022-11-08 17:27:02 +03:00
parent 5945cc9b70
commit 52aa76584a

View File

@ -216,15 +216,23 @@ class TQueueImpl final : public TQueue {
} }
void clear(QueueId queue_id, size_t keep_count) final { void clear(QueueId queue_id, size_t keep_count) final {
auto size = get_size(queue_id); auto queue_it = queues_.find(queue_id);
if (queue_it == queues_.end()) {
return;
}
auto &q = queue_it->second;
auto size = get_size(q);
if (size <= keep_count) { if (size <= keep_count) {
return; return;
} }
MutableSpan<TQueue::Event> span; auto end_it = q.events.end();
auto r_size = get(queue_id, get_tail(queue_id).advance(0 - keep_count).move_as_ok(), true, 0, span); while (keep_count-- > 0) {
CHECK(r_size.is_ok()); --end_it;
CHECK(r_size.ok() == keep_count); }
for (auto it = q.events.begin(); it != end_it;) {
pop(q, queue_id, it, q.tail_id);
}
} }
Result<size_t> get(QueueId queue_id, EventId from_id, bool forget_previous, int32 unix_time_now, Result<size_t> get(QueueId queue_id, EventId from_id, bool forget_previous, int32 unix_time_now,