Repository navigation
Title: Fix(Perf): index user preferences and reduce SQL queries per page - #237
Merged
Merged
Conversation
Rom1-B
requested review from
a team,
Mary-Clb,
MyvTsv and
RomainLvr
and removed request for
a team
November 18, 2026 15:09
MyvTsv
approved these changes
Nov 30, 2026
Contributor
|
Backport-action backported this pull request in workflow run 46600991589.
|
2 of 4 tasks
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.
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.