From ec4ae065b02bbb12c98806d2b542eb2081fec22f Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 13 Oct 2022 15:22:06 +0300 Subject: [PATCH] Simplify TQueue::run_gc. --- tddb/td/db/TQueue.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tddb/td/db/TQueue.cpp b/tddb/td/db/TQueue.cpp index ca130b0fb..9aa22fb32 100644 --- a/tddb/td/db/TQueue.cpp +++ b/tddb/td/db/TQueue.cpp @@ -247,19 +247,22 @@ class TQueueImpl final : public TQueue { int32 new_gc_at = 0; if (!q.events.empty()) { - auto head_id = q.events.begin()->first; - Event event; - MutableSpan span{&event, 1}; size_t size_before = get_size(q); - do_get(queue_id, q, head_id, false, unix_time_now, span); + for (auto event_it = q.events.begin(); event_it != q.events.end();) { + auto &event = event_it->second; + if (event.expires_at < unix_time_now || event.data.empty()) { + pop(q, queue_id, event_it, q.tail_id); + } else { + if (new_gc_at != 0) { + break; + } + new_gc_at = event.expires_at; + ++event_it; + } + } size_t size_after = get_size(q); CHECK(size_after <= size_before); deleted_events += size_before - size_after; - if (!span.empty()) { - CHECK(!event.data.empty()); - new_gc_at = event.expires_at; - CHECK(new_gc_at >= unix_time_now); - } } schedule_queue_gc(queue_id, q, new_gc_at); }