diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-20 05:46:34 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-20 05:46:34 +0000 |
commit | 54fe2c600e6930c2885f3f6048221710637a142f (patch) | |
tree | 430bc233222900638a615b266afdba37da22db81 /modules/exif | |
parent | dc3df4d6ac0f976f4887a244d5fbbb153a991d90 (diff) |
Avoid doing an expensive insert in available_tasks(). Partial fix for ticket #235.
Diffstat (limited to 'modules/exif')
-rw-r--r-- | modules/exif/helpers/exif_task.php | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php index ba7b00ac..620d0791 100644 --- a/modules/exif/helpers/exif_task.php +++ b/modules/exif/helpers/exif_task.php @@ -19,21 +19,12 @@ */ class exif_task_Core { static function available_tasks() { - $db = Database::instance(); - // Delete extra exif_records - $db->query( + Database::instance()->query( "DELETE FROM {exif_records} " . "WHERE {exif_records}.`item_id` NOT IN " . "(SELECT `id` FROM {items} WHERE {items}.`type` = 'photo')"); - // Insert missing exif_records - $db->query( - "INSERT INTO {exif_records}(`item_id`) " . - "(SELECT {items}.`id` FROM {items} " . - " LEFT JOIN {exif_records} ON ({exif_records}.`item_id` = {items}.`id`) " . - " WHERE {items}.`type` = 'photo' AND {exif_records}.`id` IS NULL)"); - list ($remaining, $total, $percent) = self::_get_stats(); return array(Task_Definition::factory() ->callback("exif_task::extract_exif") @@ -51,9 +42,12 @@ class exif_task_Core { $start = microtime(true); foreach (ORM::factory("item") - ->join("exif_records", "items.id", "exif_records.item_id") - ->where("exif_records.dirty", 1) - ->limit(100) + ->join("exif_records", "items.id", "exif_records.item_id", "left") + ->where("type", "photo") + ->open_paren() + ->where("exif_records.item_id", null) + ->orwhere("exif_records.dirty", 1) + ->close_paren() ->find_all() as $item) { if (microtime(true) - $start > 1.5) { break; @@ -81,7 +75,18 @@ class exif_task_Core { } private static function _get_stats() { - $missing_exif = ORM::factory("exif_record")->where("dirty", 1)->count_all(); + $missing_exif = Database::instance() + ->select("items.id") + ->from("items") + ->join("exif_records", "items.id", "exif_records.item_id", "left") + ->where("type", "photo") + ->open_paren() + ->where("exif_records.item_id", null) + ->orwhere("exif_records.dirty", 1) + ->close_paren() + ->get() + ->count(); + $total_items = ORM::factory("item")->where("type", "photo")->count_all(); if (!$total_items) { return array(0, 0, 0); |