reduce number of sql queries on shift calendar

main
msquare 8 years ago
parent 99c7e8ce1a
commit deb41c4b64

@ -19,3 +19,7 @@ ALTER TABLE `AngelTypes`
INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL, 'shiftentry_edit_angeltype_supporter', 'If user with this privilege is angeltype supporter, he can put users in shifts for their angeltype'); INSERT INTO `Privileges` (`id`, `name`, `desc`) VALUES (NULL, 'shiftentry_edit_angeltype_supporter', 'If user with this privilege is angeltype supporter, he can put users in shifts for their angeltype');
-- DB Performance
ALTER TABLE `Shifts` ADD INDEX(`start`);

@ -84,13 +84,12 @@ function NeededAngelTypes_by_shift($shiftId) {
} }
} }
$shift_entries = ShiftEntries_by_shift($shiftId);
$needed_angeltypes = []; $needed_angeltypes = [];
foreach ($needed_angeltypes_source as $angeltype) { foreach ($needed_angeltypes_source as $angeltype) {
$shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']);
$angeltype['taken'] = 0; $angeltype['taken'] = 0;
foreach($shift_entries as $shift_entry) { foreach($shift_entries as $shift_entry) {
if($shift_entry['freeloaded'] == 0) { if($shift_entry['TID']==$angeltype['id'] && $shift_entry['freeloaded'] == 0) {
$angeltype['taken']++; $angeltype['taken']++;
} }
} }

@ -28,7 +28,7 @@ function ShiftEntries_freeleaded_count() {
*/ */
function ShiftEntries_by_shift($shift_id) { function ShiftEntries_by_shift($shift_id) {
return sql_select(" return sql_select("
SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded` SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `User`.`Gekommen`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
FROM `ShiftEntry` FROM `ShiftEntry`
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID` JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id` JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id`

@ -131,6 +131,9 @@ function sql_select_db($db_name) {
function sql_select($query) { function sql_select($query) {
global $sql_connection; global $sql_connection;
echo $query . ";\n";
echo debug_string_backtrace() . "\n";
$result = $sql_connection->query($query); $result = $sql_connection->query($query);
if ($result) { if ($result) {
$data = []; $data = [];

@ -107,7 +107,7 @@ class ShiftCalendarShiftRenderer {
$entry_list = []; $entry_list = [];
foreach ($angeltype['shift_entries'] as $entry) { foreach ($angeltype['shift_entries'] as $entry) {
$style = $entry['freeloaded'] ? " text-decoration: line-through;" : ''; $style = $entry['freeloaded'] ? " text-decoration: line-through;" : '';
$entry_list[] = "<span style=\"$style\">" . User_Nick_render(User($entry['UID'])) . "</span>"; $entry_list[] = "<span style=\"$style\">" . User_Nick_render($entry) . "</span>";
} }
$shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype); $shift_signup_state = Shift_signup_allowed($user, $shift, $angeltype);
$inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries()); $inner_text = sprintf(ngettext("%d helper needed", "%d helpers needed", $shift_signup_state->getFreeEntries()), $shift_signup_state->getFreeEntries());

Loading…
Cancel
Save