From b54ddccd7beece51d78b21b4ba9e98c908fec4c5 Mon Sep 17 00:00:00 2001 From: ZotSocial Admin Date: Wed, 9 Jan 2019 21:23:12 -0500 Subject: FIX: memory exhaustion on exceptionally large message queues & multiple Queue.php invocations duplicate work --- Zotlabs/Daemon/Queue.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index 8f529ff13..e041804f0 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -61,10 +61,18 @@ class Queue { // or just prior to this query based on recent and long-term delivery history. If we have good reason to believe // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once // or twice a day. - - $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s ", + + $r = q("SELECT *,RAND() as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", db_utcnow() ); + while ($r) { + foreach($r as $rv) { + queue_deliver($rv); + } + $r = q("SELECT *,RAND() as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", + db_utcnow() + ); + } } if(! $r) return; -- cgit v1.2.3 From 6791b05a4032a076651f7c8e4790614f0f405a55 Mon Sep 17 00:00:00 2001 From: "DM42.Net (Matt Dent)" Date: Thu, 10 Jan 2019 15:29:24 -0500 Subject: Fix for PGSQL/MYSQL difference --- Zotlabs/Daemon/Queue.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index e041804f0..6b525b8c3 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -12,6 +12,15 @@ class Queue { require_once('include/items.php'); require_once('include/bbcode.php'); + switch (DBTYPE_ACTIVE) { + case DBTYPE_MYSQL: + $sqlrandfunc = "RAND()"; + break; + + case DBTYPE_POSTGRESQL: + $sqlrandfunc = "RANDOM()"; + break; + } if($argc > 1) $queue_id = $argv[1]; @@ -62,14 +71,14 @@ class Queue { // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once // or twice a day. - $r = q("SELECT *,RAND() as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", + $r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", db_utcnow() ); while ($r) { foreach($r as $rv) { queue_deliver($rv); } - $r = q("SELECT *,RAND() as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", + $r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", db_utcnow() ); } -- cgit v1.2.3 From caf2c0a6c43f3162fc8f4d758eb06cb2f56b3865 Mon Sep 17 00:00:00 2001 From: "DM42.Net (Matt Dent)" Date: Fri, 11 Jan 2019 07:35:12 -0500 Subject: Use dba_driver.php::db_getfunc() --- Zotlabs/Daemon/Queue.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index 6b525b8c3..814148404 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -12,16 +12,6 @@ class Queue { require_once('include/items.php'); require_once('include/bbcode.php'); - switch (DBTYPE_ACTIVE) { - case DBTYPE_MYSQL: - $sqlrandfunc = "RAND()"; - break; - - case DBTYPE_POSTGRESQL: - $sqlrandfunc = "RANDOM()"; - break; - } - if($argc > 1) $queue_id = $argv[1]; else @@ -71,6 +61,8 @@ class Queue { // the site is permanently down, there's no reason to attempt delivery at all, or at most not more than once // or twice a day. + $sqlrandfunc = db_getfunc('rand'); + $r = q("SELECT *,$sqlrandfunc as rn FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s order by rn limit 1", db_utcnow() ); -- cgit v1.2.3