From a540cd5822599a0a196d380c19c9dee766e8e546 Mon Sep 17 00:00:00 2001 From: Abdullah Almsaeed Date: Mon, 1 Apr 2019 08:09:18 -0400 Subject: [PATCH 1/2] Check if we have queue items first --- includes/Elasticsearch/ESQueue.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/Elasticsearch/ESQueue.php b/includes/Elasticsearch/ESQueue.php index d6bda793..5965ab18 100644 --- a/includes/Elasticsearch/ESQueue.php +++ b/includes/Elasticsearch/ESQueue.php @@ -1,6 +1,6 @@ db_like('elasticsearch%'), + ])->fetchField(); + + $queues = []; + if ($should_check) { + $query = 'SELECT index_name, priority, SUM(total) AS total, SUM(completed) AS completed, @@ -63,7 +71,8 @@ public static function progress() { FROM {' . self::QUEUE_TABLE . '} GROUP BY index_name, priority ORDER BY index_name ASC, priority ASC'; - $queues = db_query($query)->fetchAll(); + $queues = db_query($query)->fetchAll(); + } $progress = []; $total = 0; @@ -76,7 +85,7 @@ public static function progress() { continue; } - if($queue->completed > $queue->total) { + if ($queue->completed > $queue->total) { static::fixProgress($queue); } @@ -100,7 +109,7 @@ public static function progress() { 'last_run_at' => $last_run, 'started_at' => $started_at, 'time' => $queue->last_run_at - $queue->started_at, - 'priority' => $queue->priority + 'priority' => $queue->priority, ]; } @@ -117,7 +126,7 @@ public static function progress() { public static function fixProgress(&$queue) { $queue->completed = $queue->total; - db_query('UPDATE {'.self::QUEUE_TABLE.'} SET completed=total WHERE completed > total'); + db_query('UPDATE {' . self::QUEUE_TABLE . '} SET completed=total WHERE completed > total'); } /** @@ -301,4 +310,4 @@ protected function generateQueueCount() { } } } -} \ No newline at end of file +} From 2871c88f5793d36787a14020b8f4ead2ec329c08 Mon Sep 17 00:00:00 2001 From: Abdullah Almsaeed Date: Mon, 1 Apr 2019 08:12:10 -0400 Subject: [PATCH 2/2] Fix typo --- includes/Elasticsearch/ESQueue.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Elasticsearch/ESQueue.php b/includes/Elasticsearch/ESQueue.php index 5965ab18..bb65ef83 100644 --- a/includes/Elasticsearch/ESQueue.php +++ b/includes/Elasticsearch/ESQueue.php @@ -54,10 +54,10 @@ public function __construct() { * @return object */ public static function progress() { - $should_check = (int) db_query("SELECT count(*) + $should_check = (int) db_query("SELECT COUNT(*) FROM queue WHERE name LIKE :es", [ - ':es' => db_like('elasticsearch%'), + ':es' => db_like('elasticsearch').'%', ])->fetchField(); $queues = [];