From cd0a1be8904f79c2a43c1cc5e310d1588efcd2f2 Mon Sep 17 00:00:00 2001 From: Juan Guerrero Date: Thu, 26 Nov 2020 12:29:55 +0100 Subject: [PATCH] Make scrub be iterative instead of recursive so it does not throw a stack level too deep error for big experiments --- lib/verdict/storage/redis_storage.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/verdict/storage/redis_storage.rb b/lib/verdict/storage/redis_storage.rb index c540020..7af8ba1 100644 --- a/lib/verdict/storage/redis_storage.rb +++ b/lib/verdict/storage/redis_storage.rb @@ -67,15 +67,17 @@ def scope_key(scope) end def scrub(scope, cursor: 0) - cursor, results = redis.with do |conn| - conn.hscan(scope_key(scope), cursor, count: PAGE_SIZE) - end + loop do + cursor, results = redis.with do |conn| + conn.hscan(scope_key(scope), cursor, count: PAGE_SIZE) + end - results.map(&:first).each do |key| - remove(scope, key) - end + results.map(&:first).each do |key| + remove(scope, key) + end - scrub(scope, cursor: cursor) unless cursor.to_i.zero? + break if cursor.to_i.zero? + end end end end