Delete TQueue events directly if appropriate.

This commit is contained in:
levlam 2023-01-06 17:54:02 +03:00
parent d12ca158c4
commit c8acf63e02

View File

@ -261,15 +261,24 @@ class TQueueImpl final : public TQueue {
}
auto callback_clear_time = Time::now() - start_time;
q.total_event_length = 0;
std::map<EventId, RawEvent> new_events;
for (auto it = end_it; it != q.events.end();) {
q.total_event_length += it->second.data.size();
bool is_inserted = new_events.emplace(it->first, std::move(it->second)).second;
CHECK(is_inserted);
it = q.events.erase(it);
std::map<EventId, RawEvent> deleted_events;
if (keep_count > size / 2) {
for (auto it = q.events.begin(); it != end_it;) {
q.total_event_length -= it->second.data.size();
bool is_inserted = deleted_events.emplace(it->first, std::move(it->second)).second;
CHECK(is_inserted);
it = q.events.erase(it);
}
} else {
q.total_event_length = 0;
for (auto it = end_it; it != q.events.end();) {
q.total_event_length += it->second.data.size();
bool is_inserted = deleted_events.emplace(it->first, std::move(it->second)).second;
CHECK(is_inserted);
it = q.events.erase(it);
}
std::swap(deleted_events, q.events);
}
std::swap(new_events, q.events);
auto clear_time = Time::now() - start_time;
if (clear_time > 0.01) {
@ -277,7 +286,7 @@ class TQueueImpl final : public TQueue {
<< (total_event_length - q.total_event_length) << " in " << clear_time - callback_clear_time
<< " seconds and deleted them from callback in " << callback_clear_time << " seconds";
}
return new_events;
return deleted_events;
}
Result<size_t> get(QueueId queue_id, EventId from_id, bool forget_previous, int32 unix_time_now,