From: Tim Düsterhus Date: Tue, 9 Feb 2016 20:16:32 +0000 (+0100) Subject: Drain queue faster by processing up to five items, if items are due X-Git-Tag: 3.0.0_Beta_1~2050 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5229f62d4eeb57d99a5730b6d2ebb6328376eaae;p=GitHub%2FWoltLab%2FWCF.git Drain queue faster by processing up to five items, if items are due --- 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; } }