Skip to content

Commit

Permalink
MDL-41728 Backup: Unnecessary use of in_array in base_plan
Browse files Browse the repository at this point in the history
Remove unnecessary use of in_array which causes performance problems
when loading the plan for very large courses.
  • Loading branch information
sammarshallou committed Sep 11, 2013
1 parent e78a2d0 commit 0cddce2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions backup/util/plan/base_plan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 0cddce2

Please sign in to comment.