From 5229f62d4eeb57d99a5730b6d2ebb6328376eaae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 9 Feb 2016 21:16:32 +0100 Subject: [PATCH] Drain queue faster by processing up to five items, if items are due --- .../files/js/WoltLab/WCF/BootstrapFrontend.js | 12 +++++++++++- .../action/BackgroundQueuePerformAction.class.php | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js b/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js index dbf0800397..5749a71500 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/BootstrapFrontend.js @@ -18,6 +18,8 @@ define( { "use strict"; + var queueInvocations = 0; + /** * @exports WoltLab/WCF/BootstrapFrontend */ @@ -69,12 +71,20 @@ define( * @param {boolean} force whether execution should be forced */ _invokeBackgroundQueue: function(url, force) { + var again = this._invokeBackgroundQueue.bind(this, url, true); + if (Math.random() < 0.1 || force) { // 'fire and forget' background queue perform task Ajax.apiOnce({ url: url, ignoreError: true, - silent: true + silent: true, + success: (function(data) { + queueInvocations++; + + // process up to 5 queue items per page load + if (data > 0 && queueInvocations < 5) setTimeout(again, 1000); + }).bind(this) }); } } diff --git a/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php b/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php index a91b7e1e42..f2a1a8fb2c 100644 --- a/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php +++ b/wcfsetup/install/files/lib/action/BackgroundQueuePerformAction.class.php @@ -20,8 +20,9 @@ class BackgroundQueuePerformAction extends AbstractAction { public function execute() { parent::execute(); - @header('HTTP/1.1 204 No Content'); + header('Content-type: application/json'); BackgroundQueueHandler::getInstance()->performNextJob(); + echo BackgroundQueueHandler::getInstance()->getRunnableCount(); exit; } } -- 2.20.1