* [pmg-devel] [PATCH pmg-api v2] rulecache: sort rules additionally by id
@ 2022-12-20 10:57 Stoiko Ivanov
2022-12-23 12:41 ` [pmg-devel] applied: " Dominik Csapak
0 siblings, 1 reply; 2+ messages in thread
From: Stoiko Ivanov @ 2022-12-20 10:57 UTC (permalink / raw)
To: pmg-devel
When more rules have the same priority currently their order is not
stable - postgres returns them in a stable way, based on their last
changetime - e.g. disabling and reenabling a rule puts it in the front
of evaluation. Sortin by id (the primary key) in addition should make
rule evaluation robust to such updates
While there is no guarantee of ordering (within the same priority)
unexpected changes in which rule fires can cause confusion (at least
it confused me quite a bit).
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
v1->v2:
* changed the ordering so that the sorting by priority did not get reversed
huge thx to Dominik for testing and noticing! [0]
[0] https://www.postgresql.org/docs/current/queries-order.html
src/PMG/RuleCache.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/PMG/RuleCache.pm b/src/PMG/RuleCache.pm
index d35e9c1..b8690ea 100644
--- a/src/PMG/RuleCache.pm
+++ b/src/PMG/RuleCache.pm
@@ -37,7 +37,7 @@ sub new {
my $sth = $dbh->prepare(
"SELECT ID, Name, Priority, Active, Direction FROM Rule " .
"where Active > 0 " .
- "ORDER BY Priority DESC");
+ "ORDER BY Priority DESC, ID DESC");
$sth->execute();
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-23 12:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 10:57 [pmg-devel] [PATCH pmg-api v2] rulecache: sort rules additionally by id Stoiko Ivanov
2022-12-23 12:41 ` [pmg-devel] applied: " Dominik Csapak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox