diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-02-02 01:24:13 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-02-02 01:24:13 +0000 |
commit | 51f13f0ca2e36dc50db1ce5782d6a0b8135a158d (patch) | |
tree | 18e2613162b52db6e80e0714a07d88946b394293 /modules | |
parent | d728e274f6ff3f312998f689f3eb144acd210916 (diff) |
Reconcile search_records and items when we list the tasks so that we can tell if there're any out of date records that need updating
Diffstat (limited to 'modules')
-rw-r--r-- | modules/search/helpers/search_task.php | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php index 116fd4f9..c0d04ca5 100644 --- a/modules/search/helpers/search_task.php +++ b/modules/search/helpers/search_task.php @@ -19,6 +19,19 @@ */ class search_task_Core { static function available_tasks() { + // Delete extra search_records + Database::instance()->query( + "DELETE `search_records`.* FROM `search_records` " . + "LEFT JOIN `items` ON (`search_records`.`item_id` = `items`.`id`) " . + "WHERE `items`.`id` IS NULL"); + + // Insert missing search_records + Database::instance()->query( + "INSERT INTO `search_records`(`item_id`) (" . + " SELECT `items`.`id` FROM `items` " . + " LEFT JOIN `search_records` ON (`search_records`.`item_id` = `items`.`id`) " . + " WHERE `search_records`.`id` IS NULL)"); + list ($remaining, $total, $percent) = self::_get_stats(); return array(Task_Definition::factory() ->callback("search_task::update_index") @@ -32,12 +45,6 @@ class search_task_Core { static function update_index($task) { $completed = $task->get("completed", 0); - if ($completed == 0) { - Database::instance()->query( - "DELETE `search_records`.* FROM `search_records` " . - "LEFT JOIN `items` ON (`search_records`.`item_id` = `items`.`id`) " . - "WHERE `items`.`id` IS NULL"); - } foreach (ORM::factory("search_record")->where("dirty", 1)->limit(2)->find_all() as $record) { search::update_record($record); |