From a659cb5932eb609e524f79755747061ea1b4bd57 Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Fri, 5 Apr 2024 19:15:53 +0200 Subject: [PATCH] in server find_available, get server_load set only once and iterate through it until server with valid hash is found (#1052) --- app/models/server.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/server.rb b/app/models/server.rb index 8e360b81..1c1b9bcb 100644 --- a/app/models/server.rb +++ b/app/models/server.rb @@ -278,11 +278,9 @@ def self.find(id) # Find the server with the lowest load (for creating a new meeting) def self.find_available with_connection do |redis| - id, load, hash = 5.times do - ids_loads = redis.zrange('server_load', 0, 0, with_scores: true) - raise RecordNotFound.new("Couldn't find available Server", name, nil) if ids_loads.blank? - - id, load = ids_loads.first + ids_loads = redis.zrange('server_load', 0, -1, with_scores: true) + raise RecordNotFound.new("Couldn't find available Server", name, nil) if ids_loads.blank? + id, load, hash = ids_loads.each do |id, load| hash = redis.hgetall(key(id)) break id, load, hash if hash.present? end