diff options
author | Olivier van Helden <olivier@van-helden.net> | 2014-12-03 17:54:07 -0400 |
---|---|---|
committer | Olivier van Helden <olivier@van-helden.net> | 2014-12-03 17:54:07 -0400 |
commit | e523061b7261439a71bdacf8f46d4c614740b356 (patch) | |
tree | 1a0577c64197c4289ed154d2c2d5fdf48a7e5192 /include/queue.php | |
parent | 13fd91d6f5723774a1b96257f8096acb2873b4ed (diff) | |
parent | b71b45aafc618d32d23c099a4d4db8bad2f09e54 (diff) | |
download | volse-hubzilla-e523061b7261439a71bdacf8f46d4c614740b356.tar.gz volse-hubzilla-e523061b7261439a71bdacf8f46d4c614740b356.tar.bz2 volse-hubzilla-e523061b7261439a71bdacf8f46d4c614740b356.zip |
Merge pull request #1 from friendica/master
Merge master from friendica
Diffstat (limited to 'include/queue.php')
-rw-r--r-- | include/queue.php | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/include/queue.php b/include/queue.php index 222ebada4..b6a540ef9 100644 --- a/include/queue.php +++ b/include/queue.php @@ -22,7 +22,9 @@ function queue_run($argv, $argc){ logger('queue: start'); - $r = q("DELETE FROM outq WHERE outq_created < UTC_TIMESTAMP() - INTERVAL 3 DAY"); + $r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s", + db_utcnow(), db_quoteinterval('3 DAY') + ); if($queue_id) { $r = q("SELECT * FROM outq WHERE outq_hash = '%s' LIMIT 1", @@ -37,8 +39,18 @@ function queue_run($argv, $argc){ // so that we don't start off a thousand deliveries for a couple of dead hubs. // The zot driver will deliver everything destined for a single hub once contact is made (*if* contact is made). // Other drivers will have to do something different here and may need their own query. - - $r = q("SELECT * FROM outq WHERE outq_delivered = 0 and (( outq_created > UTC_TIMESTAMP() - INTERVAL 12 HOUR and outq_updated < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( outq_updated < UTC_TIMESTAMP() - INTERVAL 1 HOUR )) group by outq_posturl"); + if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) { + $prefix = 'DISTINCT ON (outq_posturl)'; + $suffix = 'ORDER BY outq_posturl'; + } else { + $prefix = ''; + $suffix = 'GROUP BY outq_posturl'; + } + $r = q("SELECT $prefix * FROM outq WHERE outq_delivered = 0 and (( outq_created > %s - INTERVAL %s and outq_updated < %s - INTERVAL %s ) OR ( outq_updated < %s - INTERVAL %s )) $suffix", + db_utcnow(), db_quoteinterval('12 HOUR'), + db_utcnow(), db_quoteinterval('15 MINUTE'), + db_utcnow(), db_quoteinterval('1 HOUR') + ); } if(! $r) return; @@ -51,13 +63,13 @@ function queue_run($argv, $argc){ $result = z_post_url($rr['outq_posturl'],$rr['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('queue: queue post success to ' . $rr['outq_posturl'], LOGGER_DEBUG); - $y = q("delete from outq where outq_hash = '%s' limit 1", + $y = q("delete from outq where outq_hash = '%s'", dbesc($rr['ouq_hash']) ); } else { logger('queue: queue post returned ' . $result['return_code'] . ' from ' . $rr['outq_posturl'],LOGGER_DEBUG); - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($rr['outq_hash']) ); @@ -70,7 +82,7 @@ function queue_run($argv, $argc){ } else { $deadguys[] = $rr['outq_posturl']; - $y = q("update outq set outq_updated = '%s' where outq_hash = '%s' limit 1", + $y = q("update outq set outq_updated = '%s' where outq_hash = '%s'", dbesc(datetime_convert()), dbesc($rr['outq_hash']) ); |