Repository navigation
Improve Performance - #149
Merged
Merged
Conversation
Rom1-B
requested review from
a team,
Herafia,
MyvTsv and
jdurand-teclib
and removed request for
a team
November 18, 2026 15:09
Herafia
previously approved these changes
Nov 20, 2026
jdurand-teclib
previously approved these changes
Nov 23, 2026
MyvTsv
approved these changes
Nov 24, 2026
Herafia
approved these changes
Nov 24, 2026
Contributor
|
Backport-action backported this pull request in workflow run 45367853395.
|
2 of 4 tasks
TarekRemo
added a commit
that referenced
this pull request
Nov 24, 2026
(cherry picked from commit e39e0ad)
Rom1-B
pushed a commit
that referenced
this pull request
Nov 24, 2026
Forward-port of #149 to `main`. ## Checklist before requesting a review *Please delete options that are not relevant.* - [x] I have performed a self-review of my code. - [ ] I have added tests (when available) that prove my fix is effective or that my feature works. - [x] I have updated the CHANGELOG with a short functional description of the fix or new feature. - [ ] This change requires a documentation update. ## Test data GLPI 11.0 (`11.0/bugfixes`), e2e database, plugin 1.20.4, debug mode and Xdebug off. Data injected in SQL: | Data | Volume | |---|---| | glpi_locations | 2 000, on 5 levels | | glpi_computers, monitors, printers, network equipments, peripherals, phones, software, racks, enclosures, PDUs, passive devices | 2 000 each (22 000 assets) | | glpi_plugin_treeview_preferences | 2 022 (one per user) | The assets are spread unevenly: 20 % in one location (2000, about 4 400 assets), 30 % in 19 other hot locations, 50 % one per type in the other locations. ## Test scenarios Each scenario: 1 warm-up run, then 5 measured runs (medians). SQL counted from the MariaDB log in a separate pass. Five other plugins stay active in both states. | ID | Scenario | |---|---| | S0, S1 | Central page, before and after the tree was opened (plugin inactive baseline) | | S2 | Computer form (plugin inactive baseline) | | T1 | Tree entry page (`index.php`) | | T2 | Tree root | | T3 / T4 / T5 | Tree opened on a typical location (121 nodes) / a hot one (451 nodes) / the very hot one (4 422 nodes) | | T6 | Config page, Tree view tab | | W1 | Create, move, trash and purge a computer (plugin inactive baseline) | | W2 | Save the plugin config | ## Problems found - `left.php` runs `SELECT completename FROM glpi_locations WHERE id = ?` once per asset type of every open location, and never uses the result: 44 of the 138 queries of a typical location. - It also creates one CSRF token per asset type and puts it in a GET search link: 44 tokens added to the session by each tree click. - The item queries use `SELECT *` on 11 wide asset tables while only the id, the name and the inventory number are read. - `treeview.css` is loaded on every GLPI page, but only the tree frame uses it. - `glpi_plugin_treeview_preferences.users_id` has no index: each login and profile change scans the whole table. - `plugin_init_treeview()` instantiates the 11 asset classes on every request to register the item hooks. ## Fixes - Remove the unused `completename` query and the CSRF token from the search links. - Select only `id`, `name` and `otherserial` (when the table has it). - Remove the global `ADD_CSS` hook, and link `treeview.css` from `left.php`. - Add a `users_id` key to the preferences table (`CREATE TABLE` and an idempotent `Migration::addKey` for existing installs). - Register the item hooks on the static type list. The tree output is unchanged: same nodes, byte for byte, on the four tree scenarios. ## Results | Measure | Before | After | Gain | |---|---|---|---| | Typical location (T3): SQL queries | 138 | 94 | +32 % | | Hot location (T4): SQL queries | 149 | 105 | +30 % | | Very hot location (T5): SQL queries | 127 | 105 | +17 % | | T3: unused `completename` queries | 44 | 0 | +100 % | | T3: CSRF tokens added to the session per click | 44 | 0 | +100 % | | T5: SQL time, ms (single run) | 36 | 27 | +24 % | | Resources loaded on every page except the tree frame | 91 | 90 | +1 % | | Preferences lookup, rows examined | 2 022 | 1 | +100 % | | Neutral, form and write pages: SQL queries (S0, S2, W1, W2) | 560, 172, 1 454, 337 | 560, 171, 1 454, 337 | 0 % | --------- Co-authored-by: TarekRemo <tarekrummo64@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
Test data
GLPI 11.0 (
11.0/bugfixes), e2e database, plugin 1.20.4, debug mode and Xdebug off. Data injected in SQL:The assets are spread unevenly: 20 % in one location (2000, about 4 400 assets), 30 % in 19 other hot locations, 50 % one per type in the other locations.
Test scenarios
Each scenario: 1 warm-up run, then 5 measured runs (medians). SQL counted from the MariaDB log in a separate pass. Five other plugins stay active in both states.
index.php)Problems found
left.phprunsSELECT completename FROM glpi_locations WHERE id = ?once per asset type of every open location, and never uses the result: 44 of the 138 queries of a typical location.SELECT *on 11 wide asset tables while only the id, the name and the inventory number are read.treeview.cssis loaded on every GLPI page, but only the tree frame uses it.glpi_plugin_treeview_preferences.users_idhas no index: each login and profile change scans the whole table.plugin_init_treeview()instantiates the 11 asset classes on every request to register the item hooks.Fixes
completenamequery and the CSRF token from the search links.id,nameandotherserial(when the table has it).ADD_CSShook, and linktreeview.cssfromleft.php.users_idkey to the preferences table (CREATE TABLEand an idempotentMigration::addKeyfor existing installs).The tree output is unchanged: same nodes, byte for byte, on the four tree scenarios.
Results
completenamequeries