diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2009-05-20 06:10:14 +0000 |
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-20 06:10:14 +0000 |
| commit | 774e0b3737d51b70bb141f4e13c6c111208847c0 (patch) | |
| tree | 8f367c99a16c1d4d3419838aec420a29a320bc3b /modules/search/helpers/search.php | |
| parent | 54fe2c600e6930c2885f3f6048221710637a142f (diff) | |
Avoid complex inserts in available_tasks() to make admin/maintenance
run faster. This fixes ticket #235.
Incidentally, refactor exif and search to use the same patterns
overall so that if you understand one, you understand the other and
they generally use the same strings for localization.
Diffstat (limited to 'modules/search/helpers/search.php')
| -rw-r--r-- | modules/search/helpers/search.php | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index 2842afbd..2c7be123 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -51,7 +51,8 @@ class search_Core { } static function check_index() { - if ($count = ORM::factory("search_record")->where("dirty", 1)->count_all()) { + list ($remaining) = search::stats(); + if ($remaining) { site_status::warning( t('Your search index needs to be updated. <a href="%url" class="gDialogLink">Fix this now</a>', array("url" => url::site("admin/maintenance/start/search_task::update_index?csrf=__CSRF__"))), @@ -59,8 +60,13 @@ class search_Core { } } - static function update_record($record) { + static function update($item) { $data = array(); + $record = ORM::factory("search_record")->where("item_id", $item->id)->find(); + if (!$record->loaded) { + $record->item_id = $item->id; + } + foreach (module::installed() as $module_name => $module_info) { $class_name = "{$module_name}_search"; if (method_exists($class_name, "item_index_data")) { @@ -71,4 +77,18 @@ class search_Core { $record->dirty = 0; $record->save(); } + + static function stats() { + $remaining = Database::instance() + ->select("items.id") + ->from("items") + ->join("search_records", "items.id", "search_records.item_id", "left") + ->where("search_records.item_id", null) + ->orwhere("search_records.dirty", 1) + ->get() + ->count(); + $total = ORM::factory("item")->count_all(); + $percent = round(100 * ($total - $remaining) / $total); + return array($remaining, $total, $percent); + } } |
