Skip to content

Invidious is an alternative front-end to YouTube

Add fix for index out of bounds during high load

Omar Rothf69f0b97f5d1
diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr
index f2240691..949eb335 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