Skip to content

Commit

Permalink
The availability generation algorithm needs performance improvements …
Browse files Browse the repository at this point in the history
…when many appointments are stored in the system (#1171).
  • Loading branch information
alextselegidis committed Nov 17, 2021
1 parent f7b2e60 commit af42c7c
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions application/libraries/Availability.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ public function __construct()
*/
public function get_available_hours(string $date, array $service, array $provider, int $exclude_appointment_id = NULL): array
{
$available_periods = $this->get_available_periods($date, $provider, $exclude_appointment_id);

$available_hours = $this->generate_available_hours($date, $service, $available_periods);

if ($service['attendants_number'] > 1)
{
$available_hours = $this->consider_multiple_attendants($date, $service, $provider, $exclude_appointment_id);
}
else
{
$available_periods = $this->get_available_periods($date, $provider, $exclude_appointment_id);

$available_hours = $this->generate_available_hours($date, $service, $available_periods);
}

return $this->consider_book_advance_timeout($date, $available_hours, $provider);
}
Expand Down Expand Up @@ -89,9 +91,12 @@ protected function get_available_periods(string $date, array $provider, int $exc
// Get the provider's working plan exceptions.
$working_plan_exceptions = json_decode($provider['settings']['working_plan_exceptions'], TRUE);

$where = [
'id_users_provider' => $provider['id'],
];
$escaped_provider_id = $this->CI->db->escape($provider['id']);

$escaped_date = $this->CI->db->escape($date);

$where = 'id_users_provider = ' . $escaped_provider_id
. ' AND DATE(start_datetime) <= ' . $escaped_date . ' AND DATE(end_datetime) >= ' . $escaped_date;

// Sometimes it might be necessary to exclude an appointment from the calculation (e.g. when editing an
// existing appointment).
Expand Down

0 comments on commit af42c7c

Please sign in to comment.