From 659a2301dce194baccb30f2df59c909b56bcd6d0 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 13 Feb 2023 09:43:04 +0000 Subject: [PATCH] wait #5725 @0.25 --- inc/ws/Metier/class.ws.document.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index c961c6b9f..c86dafc8e 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -451,22 +451,38 @@ class wsDocument extends cubeMetier if (null === self::$_farmServers) { self::$_farmServers = json_decode(file_get_contents('/home/toolbox/www/storage/fluidbookfarm/servers'), true); } + return self::$_farmServers; } - public static function pickOneFarmServer() + public static function pickOneFarmServer($region = 'UE') { $hat = []; $pings = json_decode(file_get_contents('/home/toolbox/www/storage/fluidbookfarm/pings')); + $allServers = []; + $regionServers = []; + foreach (self::getFarmServers() as $k => $farmServer) { if (!isset($pings[$k]) || !$pings[$k]) { continue; } - for ($i = 0; $i < $farmServer['weight']; $i++) { + + $allServers[$k] = $farmServer['weight']; + if ($region == $farmServer['region']) { + $regionServers[$k] = $farmServer['weight']; + } + } + + if (count($regionServers) == 0) { + $regionServers = $allServers; + } + foreach ($regionServers as $k => $weight) { + for ($i = 0; $i < $weight; $i++) { $hat[] = $k; } } + shuffle($hat); $i = array_pop($hat); return self::$_farmServers[$i]; @@ -493,7 +509,7 @@ class wsDocument extends cubeMetier public function _getFileFarm($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false) { $start = microtime(true); - $farmer = self::pickOneFarmServer(); + $farmer = self::pickOneFarmServer($this->region); $params = ['page' => $page, 'format' => $format, 'resolution' => $resolution, 'withText' => $withText, 'withGraphics' => $withGraphics, 'version' => $version, 'force' => $force, 'out' => $this->out, 'resolutionRatio' => $this->getResolutionRatio(), 'mobileRatio' => $this->getMobileFirstRatio()]; try { -- 2.39.5