From 3784fca753bf5d392932791deccc252280e4689f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 6 Mar 2024 16:14:37 +0000 Subject: [PATCH] Look up person names in query rather than when looping through. --- classes/Utility/Calendar.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/classes/Utility/Calendar.php b/classes/Utility/Calendar.php index 1383c4abd1..d82968b29f 100644 --- a/classes/Utility/Calendar.php +++ b/classes/Utility/Calendar.php @@ -20,8 +20,12 @@ public static function minFutureDate() { public static function fetchFuture() { $date = date('Y-m-d'); $db = new \ParlDB(); - $q = $db->query("SELECT * FROM future + $q = $db->query("SELECT pn.person_id, pn.given_name, pn.family_name, pn.lordofname, pn.title AS name_title, member.house, + future.* + FROM future LEFT JOIN future_people ON future.id = future_people.calendar_id AND witness = 0 + LEFT JOIN member ON future_people.person_id = member.person_id AND member.left_house = (SELECT MAX(left_house) from member where member.person_id = future_people.person_id) + LEFT JOIN person_names pn ON future_people.person_id = pn.person_id AND pn.type = 'name' AND pn.end_date = (SELECT MAX(end_date) from person_names where person_names.person_id = future_people.person_id) WHERE event_date >= :date AND deleted = 0 ORDER BY event_date, chamber, pos", @@ -35,8 +39,12 @@ public static function fetchDate($date) { global $DATA, $PAGE, $this_page; $db = new \ParlDB(); - $q = $db->query("SELECT * FROM future + $q = $db->query("SELECT pn.person_id, pn.given_name, pn.family_name, pn.lordofname, pn.title AS name_title, member.house, + future.* + FROM future LEFT JOIN future_people ON future.id = future_people.calendar_id AND witness = 0 + LEFT JOIN member ON future_people.person_id = member.person_id AND member.left_house = (SELECT MAX(left_house) from member where member.person_id = future_people.person_id) + LEFT JOIN person_names pn ON future_people.person_id = pn.person_id AND pn.type = 'name' AND pn.end_date = (SELECT MAX(end_date) from person_names where person_names.person_id = future_people.person_id) WHERE event_date = '$date' AND deleted = 0 ORDER BY chamber, pos"); @@ -58,10 +66,13 @@ public static function fetchDate($date) { public static function fetchItem($id) { $db = new \ParlDB(); - $q = $db->query("SELECT *, event_date as hdate, pos as hpos + $q = $db->query("SELECT pn.person_id, pn.given_name, pn.family_name, pn.lordofname, pn.title AS name_title, member.house, + future.* FROM future - LEFT JOIN future_people ON id=calendar_id AND witness=0 - WHERE id = $id AND deleted=0"); + LEFT JOIN future_people ON future.id = future_people.calendar_id AND witness = 0 + LEFT JOIN member ON future_people.person_id = member.person_id AND member.left_house = (SELECT MAX(left_house) from member where member.person_id = future_people.person_id) + LEFT JOIN person_names pn ON future_people.person_id = pn.person_id AND pn.type = 'name' AND pn.end_date = (SELECT MAX(end_date) from person_names where person_names.person_id = future_people.person_id) + WHERE future.id = $id AND deleted=0"); return self::tidyData($q); } @@ -71,7 +82,8 @@ private static function tidyData($q) { $people = array(); foreach ($q as $row) { if ($row['person_id']) { - $people[$row['id']][] = $row['person_id']; + $name = member_full_name($row['house'], $row['name_title'], $row['given_name'], $row['family_name'], $row['lordofname']); + $people[$row['id']][$row['person_id']] = $name; } } foreach ($q as $row) { @@ -79,7 +91,7 @@ private static function tidyData($q) { continue; } if (isset($people[$row['id']])) { - $row['person_id'] = $people[$row['id']]; + $row['people'] = $people[$row['id']]; } $data[$row['event_date']][$row['chamber']][] = $row; $seen[$row['id']] = true; @@ -124,10 +136,8 @@ public static function meta($e) { } } else { $title = $e['title']; - if ($pids = $e['person_id']) { - foreach ($pids as $pid) { - $MEMBER = new \MEMBER(array( 'person_id' => $pid )); - $name = $MEMBER->full_name(); + if ($people = $e['people']) { + foreach ($people as $pid => $name) { $title .= " – $name"; } }