From 047c9f005188f85b28058b550dd83e9750b4a08e Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 20 Mar 2024 12:38:07 +0100 Subject: [PATCH] Improve memory store cleanup --- lib/pecorino/adapters/memory_adapter.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/pecorino/adapters/memory_adapter.rb b/lib/pecorino/adapters/memory_adapter.rb index b332979..0d891d0 100644 --- a/lib/pecorino/adapters/memory_adapter.rb +++ b/lib/pecorino/adapters/memory_adapter.rb @@ -94,15 +94,16 @@ def blocked_until(key:) def prune now_monotonic = get_mono_time - @blocks.delete_if do |key, blocked_until_monotonic| + @blocks.keys.each do |key| @lock.with(key) do - blocked_until_monotonic < now_monotonic + @blocks.delete(key) if @blocks[key] && @blocks[key] < now_monotonic end end - @buckets.delete_if do |key, (_level, expire_at_monotonic)| + @buckets.keys.each do |key| @lock.with(key) do - expire_at_monotonic < now_monotonic + _level, expire_at_monotonic = @buckets[key] + @buckets.delete(key) if expire_at_monotonic && expire_at_monotonic < now_monotonic end end end