RISE has a few functions that keep big lists and kanban boards fast. Use them in your plugin when it shows long lists, or when a view or helper needs the signed in user.
Get the signed in user
Do not create a new Security_Controller in a helper, library or view only to read the signed in user. Every new controller runs several database queries, and in a list it runs once for every row.
Use this instead. It loads the user once per request:
$login_user = \App\Controllers\Security_Controller::get_shared_login_user();
if ($login_user->user_type === "staff") {
//...
}
Views rendered with $this->template->view() already get it as $login_user.
Paged list queries in a model
When a list uses server side paging, MySQL still runs every sub query of the select for all matching rows before it returns one page. Your model can use get_list_result() (from Crud_model) instead. It finds the ids of the page first, then loads the full rows of those ids only.
return $this->get_list_result($select, $joins, $where, $order, $limit_offset, $select_joins);
| Parameter | What it holds |
| $select | The select columns, without SELECT. |
| $joins | Joins used by the where and the order. |
| $where | Conditions that start with AND. The deleted=0 check of the main table is added for you. |
| $order | The ORDER BY part. Use real columns or expressions here, not select aliases. |
| $limit_offset | The LIMIT part. Empty for a list without paging. |
| $select_joins | Joins used only by the select columns. |
With paging it returns an array with data, recordsTotal and recordsFiltered. Without paging it returns the query result, like before.
Custom fields on kanban cards
To show custom fields on kanban cards, load them for all cards of a column at once:
$custom_fields_of_items = get_kanban_custom_fields_data("tasks", $items);
foreach ($items as $item) {
$fields = $custom_fields_of_items[$item->id] ?? array();
}
Each field has custom_field_type, custom_field_title and value. Only fields with Show on kanban card are returned.