From a153ca082971e1eb454aa66199ee0380a9794a6e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 2 Oct 2010 17:04:37 -0700 Subject: Detect the case where there are no more broken images and skip to the end. Fixes #1414. --- modules/gallery/helpers/gallery_task.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 3b173928..d56edabb 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -84,6 +84,13 @@ class gallery_task_Core { $ignored = $task->get("ignored", array()); $i = 0; + + // If there's no work left to do, skip to the end. This can happen if we resume a task long + // after the work got done in some other task. + if (!$result->count()) { + $completed = $total_count; + } + foreach ($result as $row) { if (array_key_exists($row->id, $ignored)) { continue; -- cgit v1.2.3 From 5f4ab7fd76d24e3848aa96b3f657fca587d68f72 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 21 Nov 2010 13:01:44 -0800 Subject: Shuffle up the way we figure out which image to rebuild next so that multiple concurrent tasks actually work in parallel and don't stomp on each other. Fixes #1498. --- modules/gallery/helpers/gallery_task.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index d56edabb..e69ff91a 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -71,7 +71,12 @@ class gallery_task_Core { static function rebuild_dirty_images($task) { $errors = array(); try { - $result = graphics::find_dirty_images_query()->select("id")->execute(); + // Choose the dirty images in a random order so that if we run this task multiple times + // concurrently each task is rebuilding different images simultaneously. + $result = graphics::find_dirty_images_query()->select("id") + ->select(new Database_Expression("RAND() as r")) + ->order_by("r", "ASC") + ->execute(); $total_count = $task->get("total_count", $result->count()); $mode = $task->get("mode", "init"); if ($mode == "init") { -- cgit v1.2.3