From 5415180b2ce2b77d15918cefe436c1aa08f0c77d Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Mon, 16 Feb 2026 14:18:59 +0100 Subject: [PATCH 1/4] fetch count and paginated data in one query --- application/models/system/Message_model.php | 105 ++++++++++---------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index e0a185f9b..741c96ade 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -242,74 +242,71 @@ class Message_model extends DB_Model */ public function getMessagesForTable($person_id, $offset, $limit) { - $sql_base = " - SELECT + $sql = <<execQuery($sql, $parametersArray); - - if (isError($count)) - return $count; - - $count = ceil(current(getData($count))->count/$limit); - $sql = " - SELECT * FROM ( - " . $sql_base . " - ) a - ORDER BY insertamum DESC - LIMIT ? - OFFSET ? - "; + (SELECT COALESCE(titelpre,'') || ' ' || COALESCE(vorname,'') || ' ' || COALESCE(nachname,'') || ' ' || COALESCE(titelpost,'') FROM public.tbl_person WHERE person_id = fm.sender_id) as sender, + (SELECT COALESCE(titelpre,'') || ' ' || COALESCE(vorname,'') || ' ' || COALESCE(nachname,'') || ' ' || COALESCE(titelpost,'') FROM public.tbl_person WHERE person_id = fm.recipient_id) as recipient, + fm.sender_id, + fm.recipient_id, + ms.status, + ms.insertamum as statusdatum + from + filtered_messages fm + join + public.tbl_msg_message m on fm.message_id = m.message_id + join + lastmsgstatus ms on fm.message_id = ms.message_id and fm.recipient_id = ms.person_id + order by + m.insertamum DESC + limit ? + offset ?; +EOSQL; $parametersArray = array($person_id, $person_id, $limit, $offset); + $count = 0; $data = $this->execQuery($sql, $parametersArray); if (isError($data)) return $data; $data = getData($data); + if($data) + { + $count = ceil($data[0]->total_msgs / $limit); + } return success(['data' => $data, 'count' => $count]); } From 962cbf4e783958bf75822dbe988aba3097166f5f Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Mon, 16 Feb 2026 15:16:49 +0100 Subject: [PATCH 2/4] join person table for sender and recipient instead of using subselect --- application/models/system/Message_model.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 741c96ade..33e3d9649 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -276,8 +276,8 @@ class Message_model extends DB_Model m.body AS body, m.insertamum AS insertamum, m.relationmessage_id AS relationmessage_id, - (SELECT COALESCE(titelpre,'') || ' ' || COALESCE(vorname,'') || ' ' || COALESCE(nachname,'') || ' ' || COALESCE(titelpost,'') FROM public.tbl_person WHERE person_id = fm.sender_id) as sender, - (SELECT COALESCE(titelpre,'') || ' ' || COALESCE(vorname,'') || ' ' || COALESCE(nachname,'') || ' ' || COALESCE(titelpost,'') FROM public.tbl_person WHERE person_id = fm.recipient_id) as recipient, + (COALESCE(ps.titelpre,'') || ' ' || COALESCE(ps.vorname,'') || ' ' || COALESCE(ps.nachname,'') || ' ' || COALESCE(ps.titelpost,'')) as sender, + (COALESCE(pr.titelpre,'') || ' ' || COALESCE(pr.vorname,'') || ' ' || COALESCE(pr.nachname,'') || ' ' || COALESCE(pr.titelpost,'')) as recipient, fm.sender_id, fm.recipient_id, ms.status, @@ -288,6 +288,10 @@ class Message_model extends DB_Model public.tbl_msg_message m on fm.message_id = m.message_id join lastmsgstatus ms on fm.message_id = ms.message_id and fm.recipient_id = ms.person_id + left join + public.tbl_person ps on ps.person_id = fm.sender_id + left join + public.tbl_person pr on pr.person_id = fm.recipient_id order by m.insertamum DESC limit ? From 0496eb7cc947c874281dad9b28df1db758734b70 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Mon, 16 Feb 2026 15:56:40 +0100 Subject: [PATCH 3/4] use union instead of or to avoid parallel seq scan --- application/models/system/Message_model.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 33e3d9649..3a5579cc7 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -251,9 +251,23 @@ class Message_model extends DB_Model join public.tbl_msg_recipient mr on mr.message_id = m.message_id where - m.person_id = ? or mr.person_id = ? + m.person_id = ? group by m.message_id, m.person_id, mr.person_id + + union + + select + m.message_id, m.person_id as sender_id, mr.person_id as recipient_id + from + public.tbl_msg_message m + join + public.tbl_msg_recipient mr on mr.message_id = m.message_id + where + mr.person_id = ? + group by + m.message_id, m.person_id, mr.person_id + ), lastmsgstatus as ( select ms.* From e12b7e1ed55baf978d9911301e2561dc2769f1e1 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Tue, 17 Feb 2026 08:06:30 +0100 Subject: [PATCH 4/4] add indexes for person_id to table msg_message and msg_recipient, ensure tabulator data request is made before requests of create msg components --- application/models/system/Message_model.php | 2 +- .../Messages/Details/TableMessages.js | 1 + public/js/components/Messages/Messages.js | 10 +++++-- system/dbupdate_3.4.php | 1 + .../71645_studvw_messagetab_ladezeit.php | 28 +++++++++++++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 system/dbupdate_3.4/71645_studvw_messagetab_ladezeit.php diff --git a/application/models/system/Message_model.php b/application/models/system/Message_model.php index 3a5579cc7..19129b606 100644 --- a/application/models/system/Message_model.php +++ b/application/models/system/Message_model.php @@ -255,7 +255,7 @@ class Message_model extends DB_Model group by m.message_id, m.person_id, mr.person_id - union + union all select m.message_id, m.person_id as sender_id, mr.person_id as recipient_id diff --git a/public/js/components/Messages/Details/TableMessages.js b/public/js/components/Messages/Details/TableMessages.js index a55ddec63..6a4cf5ca0 100644 --- a/public/js/components/Messages/Details/TableMessages.js +++ b/public/js/components/Messages/Details/TableMessages.js @@ -243,6 +243,7 @@ export default { title: this.$p.t('global', 'aktionen') }); */ + this.$emit('tabulator_tablebuilt'); } }, { diff --git a/public/js/components/Messages/Messages.js b/public/js/components/Messages/Messages.js index 1f9afcb9e..5e247ddb5 100644 --- a/public/js/components/Messages/Messages.js +++ b/public/js/components/Messages/Messages.js @@ -56,6 +56,7 @@ export default { }, data() { return { + tablebuilt: false, isVisibleDiv: false, messageId: null } @@ -139,8 +140,10 @@ export default { }, resetMessageId(){ this.messageId = null; + }, + tableBuilt: function() { + this.tablebuilt = true; } - }, template: `
@@ -155,6 +158,7 @@ export default { -
+
diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index 793930243..4ddb38203 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -91,6 +91,7 @@ require_once('dbupdate_3.4/69065_Projektarbeiten_Firmen_verwalten.php'); require_once('dbupdate_3.4/68744_StV_settings.php'); require_once('dbupdate_3.4/62889_reihungstest_ueberwachung_mit_constructor.php'); require_once('dbupdate_3.4/71399_dashboard_update_widget_paths.php'); +require_once('dbupdate_3.4/71645_studvw_messagetab_ladezeit.php'); // *** Pruefung und hinzufuegen der neuen Attribute und Tabellen echo '

Pruefe Tabellen und Attribute!

'; diff --git a/system/dbupdate_3.4/71645_studvw_messagetab_ladezeit.php b/system/dbupdate_3.4/71645_studvw_messagetab_ladezeit.php new file mode 100644 index 000000000..4ad88fba9 --- /dev/null +++ b/system/dbupdate_3.4/71645_studvw_messagetab_ladezeit.php @@ -0,0 +1,28 @@ +db_query("SELECT * FROM pg_class WHERE relname='idx_tbl_msg_message_person_id'")) +{ + if ($db->db_num_rows($result) == 0) + { + $qry = "CREATE INDEX idx_tbl_msg_message_person_id ON public.tbl_msg_message USING btree (person_id)"; + + if (! $db->db_query($qry)) + echo 'idx_tbl_msg_message_person_id: ' . $db->db_last_error() . '
'; + else + echo 'Index idx_tbl_msg_message_person_id angelegt
'; + } +} + +if ($result = $db->db_query("SELECT * FROM pg_class WHERE relname='idx_tbl_msg_recipient_person_id'")) +{ + if ($db->db_num_rows($result) == 0) + { + $qry = "CREATE INDEX idx_tbl_msg_recipient_person_id ON public.tbl_msg_recipient USING btree (person_id)"; + + if (! $db->db_query($qry)) + echo 'idx_tbl_msg_recipient_person_id: ' . $db->db_last_error() . '
'; + else + echo 'Index idx_tbl_msg_recipient_person_id angelegt
'; + } +}