diff options
author | mamouneyya <mamoun.diraneyya@gmail.com> | 2010-12-09 18:31:01 +0200 |
---|---|---|
committer | mamouneyya <mamoun.diraneyya@gmail.com> | 2010-12-09 18:31:01 +0200 |
commit | 3e2610ea83c60805d5e727df6509da6c49fd6c7b (patch) | |
tree | 28638f7a1cd2e298587f4b3960caf409f7d2d2fa /modules/gallery/helpers/gallery_task.php | |
parent | 6aabab4b715ff8ac00cc667e9d0a40c9868410d8 (diff) | |
parent | c3ef8921260db8e39b6d2a7b4708e3d19f35f8b5 (diff) |
Merge remote branch 'gallery3/master'
Diffstat (limited to 'modules/gallery/helpers/gallery_task.php')
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 3b173928..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") { @@ -84,6 +89,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; |