Repository navigation
[main] Title: Fix(Perf): index user preferences and reduce SQL queries per page - #243
Open
glpi-project[bot] wants to merge 3 commits into
Open
glpi-project[bot] wants to merge 3 commits into
glpi-project[bot] wants to merge 3 commits into
Conversation
…age (#237) - [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. ## Description The fix makes the Lifecycle tab of the user preferences 8 times faster to build (467 ms to 56 ms) and removes 2 SQL queries the plugin ran on every HTTP request. The rendered output does not cha nge: the displayed models and selected locations of the preferences tab were checked against the database. Two configurations were measured on the same instance, with the same data: before (`main` branch) and after (fix), plus the plugin disabled on the pages that exist without it (core cost only). * **Instance:** GLPI 11.0.13-dev (11.0/bugfixes), e2e environment, Uninstall plugin 2.10.6, with and without the fix, debug mode and Xdebug off. * **Data:** 2 000 computers, 2 000 users, 200 locations, 200 uninstall models (100 in the root entity, recursive, 100 spread over 18 entities) and 50 000 user preferences. 20 users, the measured super-admin included, own half of the preferences (1 250 each). * **Measured scenarios:** the home page, a computer form, the Lifecycle tab of a computer with a model selected (`ajax/locations.php`), the Lifecycle tab of the user preferences, the model list and form, and a full cycle: create a computer, then apply the Uninstall model (`front/action.php`). * **Measurement method:** Playwright (Chromium) through the Playwright MCP, 5 measured runs per scenario after one discarded warm-up run; times come from the browser Performance API. * **SQL:** the MariaDB slow log with a zero threshold was enabled during a separate pass, one run per scenario; the count includes every query of the scenario's HTTP requests. ## SQL Queries On the preferences tab, queries on the plugin tables go from 219 to 2, and the SQL time from 413 ms to 27 ms. | Queries | Without plugin | Before | After | Difference | |---|---|---|---|---| | Computer form | 142 | 156 | 152 | -4 (3%) | | Computer, Lifecycle tab + model selected | n/a | 258 | 246 | -12 (5%) | | User preferences, Lifecycle tab | n/a | 770 | 549 | -221 (29%) | | Create a computer then apply the Uninstall model | n/a | 993 | 966 | -27 (3%) | Before the fix, `glpi_plugin_uninstall_preferences` had no index besides its primary key, and the preferences tab ran 2 queries per visible model (109 in the test): a lookup by user, entity and model, then a `getFromDB()`. Each lookup scanned the whole table (50 003 rows), which made 5.45 million rows examined and 382 ms of SQL on that tab. The table now has an index on `(users_id, entities_id, templates_id)`, created at install and added by the migration on existing installs. The preferences tab loads all the preferences of the us er in the active entity with a single query, and still creates the missing default preferences as before. The lookup run when a model is selected (`ajax/locations.php`) and when it is applied (` front/action.php`) now reads 1 row instead of 50 003. `plugin_init_uninstall()` called `Plugin::isActivated()`, which costs 2 queries on `glpi_plugins` per HTTP request while plugins are being initialized. The guard stays, because the core also run s this init while the plugin is installed, activated or uninstalled, but it now reads `Plugin::getPlugins()`, the list of active plugins loaded at boot, with no query. ## Response Times The preferences tab is clearly faster; on the other pages the difference stays within the measurement noise. | Median (min–max) | Before | After | |---|---|---| | User preferences, Lifecycle tab built by the server (ms) | 467.2 (443–550) | 56.4 (48–60) | | User preferences, page fully displayed (ms) | 742.1 (704–798) | 319.3 (300–338) | | Computer form, page fully displayed (ms) | 248.7 (226–294) | 236.3 (227–279) | | `ajax/locations.php` server time (ms) | 41.2 (33–50) | 33.1 (25–39) | The test database runs on the same machine, so each query saved costs less than 0.1 ms, which is why the 2 queries removed per request do not show in the page times. With a remote database each query adds a network round trip, so the gain per request grows with that latency. This is an estimate, not a measurement. The preferences tab still renders one location dropdown per model (728 KB for 109 models), which keeps about 140 ms of main-thread work in the browser; reducing it would need a change to the UI, which this PR does not include. --------- Co-authored-by: Julien Durand <300495670+jdurand-teclib@users.noreply.github.com> (cherry picked from commit 4f27882)
2 of 4 tasks
jdurand-teclib
requested review from
a team,
Herafia,
Mary-Clb and
MyvTsv
and removed request for
a team
December 2, 2026 11:08
Herafia
previously approved these changes
Dec 3, 2026
Herafia
left a comment
Contributor
There was a problem hiding this comment.
The changelog entry isnt in the right section, otherwise it’s fine by me
… entry in the wrong section
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.
Forward-port of #237 to
main.Description
The fix makes the Lifecycle tab of the user preferences 8 times faster to build (467 ms to 56 ms) and removes 2 SQL queries the plugin ran on every HTTP request. The rendered output does not cha
nge: the displayed models and selected locations of the preferences tab were checked against the database.
Two configurations were measured on the same instance, with the same data: before (
mainbranch) and after (fix), plus the plugin disabled on the pages that exist without it (core cost only).super-admin included, own half of the preferences (1 250 each).
ajax/locations.php), the Lifecycle tab of the user preferences, the model listand form, and a full cycle: create a computer, then apply the Uninstall model (
front/action.php).SQL Queries
On the preferences tab, queries on the plugin tables go from 219 to 2, and the SQL time from 413 ms to 27 ms.
Before the fix,
glpi_plugin_uninstall_preferenceshad no index besides its primary key, and the preferences tab ran 2 queries per visible model (109 in the test): a lookup by user, entity andmodel, then a
getFromDB(). Each lookup scanned the whole table (50 003 rows), which made 5.45 million rows examined and 382 ms of SQL on that tab.The table now has an index on
(users_id, entities_id, templates_id), created at install and added by the migration on existing installs. The preferences tab loads all the preferences of the user in the active entity with a single query, and still creates the missing default preferences as before. The lookup run when a model is selected (
ajax/locations.php) and when it is applied (front/action.php) now reads 1 row instead of 50 003.plugin_init_uninstall()calledPlugin::isActivated(), which costs 2 queries onglpi_pluginsper HTTP request while plugins are being initialized. The guard stays, because the core also runs this init while the plugin is installed, activated or uninstalled, but it now reads
Plugin::getPlugins(), the list of active plugins loaded at boot, with no query.Response Times
The preferences tab is clearly faster; on the other pages the difference stays within the measurement noise.
ajax/locations.phpserver time (ms)The test database runs on the same machine, so each query saved costs less than 0.1 ms, which is why the 2 queries removed per request do not show in the page times. With a remote database each
query adds a network round trip, so the gain per request grows with that latency. This is an estimate, not a measurement.
The preferences tab still renders one location dropdown per model (728 KB for 109 models), which keeps about 140 ms of main-thread work in the browser; reducing it would need a change to the UI,
which this PR does not include.