From 8853b35b09f96c55350f0bd88c0345cdd00530ad Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 5 Mar 2025 07:17:24 -0600 Subject: [PATCH] =?UTF-8?q?Query=20optimizado=20sin=20funci=C3=B3n=20de=20?= =?UTF-8?q?fechas=5Fclase.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action/action_auditoria.php | 28 +++++++++++----------------- auditoria.php | 19 +++++++++++++++++++ export/supervisor_excel.php | 25 +++++++++++-------------- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/action/action_auditoria.php b/action/action_auditoria.php index c57f234..a5c389a 100644 --- a/action/action_auditoria.php +++ b/action/action_auditoria.php @@ -32,8 +32,8 @@ try { // Define relevant columns $relevant_columns = [ 'registro_id', - 'fechas.registro_fecha_ideal', - 'fechas.horario_id', + 'fechas.fecha as registro_fecha_ideal', + 'horario.horario_id', 'profesor.profesor_id', 'salon', 'profesor_clave', @@ -85,7 +85,7 @@ try { "SELECT horario_id FROM horario WHERE horario_dia IN ($DaysWeek) AND periodo_id IN ($PeriodosHorarios) - AND :fecha_inicio BETWEEN horario_fecha_inicio AND COALESCE(horario_fecha_fin, :fecha_fin) + AND (:fecha_inicio, :fecha_fin) OVERLAPS (horario_fecha_inicio, COALESCE(horario_fecha_fin, :fecha_fin)) AND facultad_id = COALESCE(:facultad_id, facultad_id)", array_merge($fechas, [ ':facultad_id' => $user->facultad['facultad_id'], @@ -95,15 +95,7 @@ try { $Horarios = $db->query( "WITH fechas AS ( - SELECT fechas_clase( - _horario_id => h.horario_id, - _todos => false, - _fecha_inicio => :fecha_inicio, - _fecha_fin => :fecha_fin - ) AS registro_fecha_ideal, h.horario_id, profesor_id - FROM horario h - JOIN horario_profesor USING (horario_id) - WHERE horario_id IN ($HorariosID) + SELECT generate_series(:fecha_inicio, :fecha_fin, '1 day'::INTERVAL)::DATE AS fecha ) SELECT $RelevantColumns, @@ -112,16 +104,18 @@ try { ELSE 'primary' END AS color FROM horario - JOIN fechas USING (horario_id) + JOIN horario_profesor USING (horario_id) + JOIN fechas ON EXTRACT(DOW FROM fechas.fecha) = horario.horario_dia JOIN profesor USING (profesor_id) JOIN salon USING (salon_id) LEFT JOIN REGISTRO ON - REGISTRO.profesor_id = PROFESOR.profesor_id AND - REGISTRO.horario_id = FECHAS.horario_id AND - FECHAS.registro_fecha_ideal = REGISTRO.registro_fecha_ideal + REGISTRO.profesor_id = horario_profesor.profesor_id AND + REGISTRO.horario_id = horario.horario_id AND + REGISTRO.registro_fecha_ideal = fechas.fecha LEFT JOIN usuario ON usuario.usuario_id = REGISTRO.supervisor_id JOIN estado_supervisor ON estado_supervisor.estado_supervisor_id = COALESCE(REGISTRO.estado_supervisor_id, 0) - ORDER BY fechas.registro_fecha_ideal, horario_hora", + WHERE horario.horario_id IN ($HorariosID) + ORDER BY fechas.fecha, horario_hora", $fechas ); diff --git a/auditoria.php b/auditoria.php index faeaa66..0a434b6 100644 --- a/auditoria.php +++ b/auditoria.php @@ -347,25 +347,44 @@ + diff --git a/export/supervisor_excel.php b/export/supervisor_excel.php index 169ec7c..d7e2036 100644 --- a/export/supervisor_excel.php +++ b/export/supervisor_excel.php @@ -22,22 +22,16 @@ $profesor_clave = isset($params['profesor']) $data = $db->query( "WITH fechas AS ( - SELECT fechas_clase( - _horario_id => h.horario_id, - _todos => false, - _fecha_inicio => :fecha_inicio, - _fecha_fin => :fecha_fin - ) AS registro_fecha_ideal, h.horario_id - FROM horario h WHERE horario_id IN ({$_SESSION['horarios']}) + SELECT generate_series(:fecha_inicio, :fecha_fin, '1 day'::INTERVAL)::DATE AS registro_fecha_ideal ) SELECT fechas.registro_fecha_ideal, profesor_clave, - profesor_nombre, + COALESCE(materia_asignacion.materia_asignacion_profesor, profesor.profesor_nombre) AS profesor_nombre, profesor_correo, facultad_nombre, - materia_nombre, - carrera_nombre, + COALESCE(materia_asignacion.materia_asignacion_materia, materia.materia_nombre) AS materia_nombre, + COALESCE(materia_asignacion.materia_asignacion_carrera, carrera.carrera_nombre) AS carrera_nombre, horario_grupo, horario_hora, horario_fin, @@ -52,14 +46,16 @@ $data = $db->query( comentario, justificacion FROM horario - NATURAL JOIN fechas NATURAL JOIN horario_profesor NATURAL JOIN profesor + JOIN fechas ON EXTRACT(DOW FROM fechas.registro_fecha_ideal) = horario_dia NATURAL JOIN salon_view_mat - NATURAL JOIN facultad - NATURAL JOIN materia - NATURAL JOIN carrera + JOIN facultad ON facultad.facultad_id = COALESCE(horario.facultad_id, 0) + LEFT JOIN materia USING (MATERIA_ID) + LEFT JOIN carrera USING (carrera_id) + + LEFT JOIN materia_asignacion USING (horario_id) LEFT JOIN REGISTRO USING (profesor_id, registro_fecha_ideal, horario_id) LEFT JOIN usuario ON usuario.usuario_id = REGISTRO.supervisor_id @@ -70,6 +66,7 @@ $data = $db->query( (horario_hora, horario_fin) OVERLAPS (COALESCE(:bloque_inicio, horario_hora), COALESCE(:bloque_fin, horario_fin)) + AND horario_id IN ({$_SESSION['horarios']}) ORDER BY fechas.registro_fecha_ideal, horario_hora", [ 'facultad_id' => $user->facultad['facultad_id'] ?? $params['facultad_id'],