From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 53D1B1FF170 for ; Thu, 21 Aug 2025 16:37:20 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CBAF22D33B; Thu, 21 Aug 2025 16:37:16 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Thu, 21 Aug 2025 16:35:39 +0200 Message-ID: <20250821143705.256562-7-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250821143705.256562-1-d.kral@proxmox.com> References: <20250821143705.256562-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1755787029139 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.013 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH ha-manager 06/18] rules: make rules sorting optional in foreach_rule helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Most users of the foreach_rule helper are agnostic to the iteration order of the rules and as sorting can become a non-neglible overhead for larger rule sets, make sorting rules optional. The only caller dependent on a sorted rule set is the rules' index API endpoint. Signed-off-by: Daniel Kral --- src/PVE/API2/HA/Rules.pm | 1 + src/PVE/HA/Rules.pm | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/PVE/API2/HA/Rules.pm b/src/PVE/API2/HA/Rules.pm index ab431019..fb8b465b 100644 --- a/src/PVE/API2/HA/Rules.pm +++ b/src/PVE/API2/HA/Rules.pm @@ -194,6 +194,7 @@ __PACKAGE__->register_method({ }, type => $type, sid => $resource, + sorted => 1, ); return $res; diff --git a/src/PVE/HA/Rules.pm b/src/PVE/HA/Rules.pm index e13769a1..784f2d36 100644 --- a/src/PVE/HA/Rules.pm +++ b/src/PVE/HA/Rules.pm @@ -428,7 +428,7 @@ Filters the given C<$rules> according to the C<$opts> and loops over the resulting rules in the order as defined in the section config and executes C<$func> with the parameters C>>. -The following key-value pairs for C<$opts> as filter properties are: +The following key-value pairs for C<$opts> are: =over @@ -438,6 +438,8 @@ The following key-value pairs for C<$opts> as filter properties are: =item C<$exclude_disabled_rules>: Limits C<$rules> to those which are enabled. +=item C<$sorted>: Sorts C<$rules> according to C<< $rules->{order} >>. + =back =cut @@ -447,9 +449,9 @@ sub foreach_rule : prototype($$;%) { my $sid = $opts{sid}; - my @ruleids = sort { - $rules->{order}->{$a} <=> $rules->{order}->{$b} - } keys %{ $rules->{ids} }; + my @ruleids = keys $rules->{ids}->%*; + @ruleids = sort { $rules->{order}->{$a} <=> $rules->{order}->{$b} } @ruleids + if defined($opts{sorted}); for my $ruleid (@ruleids) { my $rule = $rules->{ids}->{$ruleid}; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel