From: Alan Date: Fri, 13 Oct 2023 03:29:20 +0000 (+0800) Subject: fix empty queue allocation X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=commitdiff_plain;h=fb3ac38cc23705668576b3cd573397ab230bbdad fix empty queue allocation --- diff --git a/DataObjects/Core_notify_server.php b/DataObjects/Core_notify_server.php index 485a4282..18908621 100644 --- a/DataObjects/Core_notify_server.php +++ b/DataObjects/Core_notify_server.php @@ -199,11 +199,19 @@ class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject $p->selectAdd('server_id, count(id) as n'); $p->groupBy('server_id'); $in_q = $p->fetchAll('server_id', 'n'); + + // if queue is empty it will not get allocated anything. + foreach($ids as $sid) { + if (!isset($in_q[$sid])) { + $in_q[$sid] = 0; + } + } $totalq = 0; foreach($in_q as $sid => $n) { $totalq += $n; } + // new average queue $target_len = floor( ($totalq + $total_add) / $num_servers );