From f69f0b97f5d1ee74dd4e5ef625da804d3334f879 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 24 Sep 2019 13:38:08 -0400 Subject: [PATCH] Add fix for index out of bounds during high load --- src/invidious/helpers/handlers.cr | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr index f2240691c..949eb3353 100644 --- a/src/invidious/helpers/handlers.cr +++ b/src/invidious/helpers/handlers.cr @@ -237,3 +237,16 @@ class HTTP::Client response end end + +struct Crystal::ThreadLocalValue(T) + @values = Hash(Thread, T).new + + def get(&block : -> T) + th = Thread.current + if !@values[th]? + @values[th] = yield + else + @values[th] + end + end +end