Permalink
Browse files

MDL-41728 Backup: Unnecessary use of in_array in base_plan

Remove unnecessary use of in_array which causes performance problems
when loading the plan for very large courses.
  • Loading branch information...
1 parent d883550 commit c4492952bf1eaf7445dd40d77b5929d34164076f @sammarshallou sammarshallou committed Sep 11, 2013
Showing with 11 additions and 7 deletions.
  1. +11 −7 backup/util/plan/base_plan.class.php
@@ -60,13 +60,17 @@ public function add_task($task) {
$task->set_plan($this);
// Append task settings to plan array, if not present, for comodity
foreach ($task->get_settings() as $key => $setting) {
- if (!in_array($setting, $this->settings)) {
- $name = $setting->get_name();
- if (!isset($this->settings[$name])) {
- $this->settings[$name] = $setting;
- } else {
- throw new base_plan_exception('multiple_settings_by_name_found', $name);
- }
+ // Check if there is already a setting for this name.
+ $name = $setting->get_name();
+ if (!isset($this->settings[$name])) {
+ // There is no setting, so add it.
+ $this->settings[$name] = $setting;
+ } else if ($this->settings[$name] != $setting) {
+ // If the setting already exists AND it is not the same setting,
+ // then throw an error. (I.e. you're allowed to add the same
+ // setting twice, but cannot add two different ones with same
+ // name.)
+ throw new base_plan_exception('multiple_settings_by_name_found', $name);
}
}
}

0 comments on commit c449295

Please sign in to comment.