Skip to content

Title: Fix(Perf): index user preferences and reduce SQL queries per page - #237

Merged
jdurand-teclib merged 2 commits into
11.0/bugfixesfrom
optimize_perf
Dec 1, 2026
Merged

jdurand-teclib merged 2 commits into
11.0/bugfixesfrom
optimize_perf

Conversation

@jdurand-teclib

Copy link
Copy Markdown
  • 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.
  • 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.

@Rom1-B
Rom1-B requested review from a team, Mary-Clb, MyvTsv and RomainLvr and removed request for a team November 18, 2026 15:09
@jdurand-teclib
jdurand-teclib merged commit 4f27882 into 11.0/bugfixes Dec 1, 2026
7 checks passed
@jdurand-teclib
jdurand-teclib deleted the optimize_perf branch December 1, 2026 07:45
@glpi-project

glpi-project Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Backport-action backported this pull request in workflow run 46600991589.

Target Status
main ✅ Created #243

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants