Skip to content

fix(core): Improve performance of the ticket form, the escalation history popup and the central Group View - #533

Open
MyvTsv wants to merge 2 commits into
11.0/bugfixesfrom
perf_optimization
Open

MyvTsv wants to merge 2 commits into
11.0/bugfixesfrom
perf_optimization

Conversation

@MyvTsv

@MyvTsv MyvTsv commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • 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

Performance Optimizations & Benchmark

This update reduces the SQL overhead and eliminates unnecessary HTTP requests generated by the plugin, primarily targeting the ticket form, the full escalation history popup, and the Central Group View.

Key Optimizations

  • Per-Request Overhead:
    • Replaced Plugin::isPluginActive() (which triggered 2 queries during plugin initialization) with a lookup against the list of plugins already activated at boot.
    • Stored the plugin configuration in the GLPI cache (invalidated upon saving). As a result, the plugin executes zero SQL queries on pages where it is not utilized.
  • Static JavaScript Assets:
    • Converted the four .js.php files (each previously triggering a full GLPI boot of ~24 queries) into static .js files.
    • Permission checks are now handled in setup.php, while configuration flags and the two translated labels are injected via <meta> tags—exclusively on the core pages that require them.
  • Full History Popup:
    • Group entities are now loaded once per distinct group rather than once per history entry.
    • The per-line inline script (which previously threw errors inside the popup) is now rendered only once, exclusively within the ticket form widget.
  • History Widget & Timeline Form:
    • Restricted the history widget query to fetch only the displayed rows instead of the entire ticket history, backed by a composite index extension on tickets_id matching the ORDER BY clause.
    • The timeline "Escalate" form now reads its configuration from the session (reloading it only if missing) and evaluates whether the group filter is enabled.
  • Central Group View Lists:
    • Switched the list-loading request to asynchronous execution as soon as the tab is initialized.
    • Replaced unbounded row-counting queries with COUNT(DISTINCT) and removed an unused JOIN on glpi_tickets_users.
    • Updated queries to select fields using DISTINCT (fixing compatibility issues where the previous query failed under MySQL 8).
  • Session Lock Release:
    • Added Session::writeClose() to ajax/central.php and ajax/history.php to release the PHP session lock early and prevent concurrent request blocking.
  • Database Schema Change:
    • Extended the existing tickets_id index on glpi_plugin_escalade_histories (e.g., to cover (tickets_id, ...) to match the ORDER BY) in a new migration step rather than creating a secondary index. Retaining the original index name ensures earlier migration steps remain idempotent (no-op) and applies seamlessly to existing installations on the next version bump.

Benchmark Results

Environment: GLPI 11.0, 2,000 tickets, 50,000 escalation history rows (evenly distributed across two "hot" tickets). Plugin active, debug mode and Xdebug disabled. Values represent the median of 5 runs; SQL counts extracted from the MariaDB query log. (Note: truncated values from the original snippet are marked with [...]).

Scenario SQL (Before) SQL (After) Time (Before) Time (After)
S0: Computer list, neutral page (full load) 97 94 25[...] ms [...] ms
S1: Central Group View (full load) 628 559 486 ms 423 ms
S2: Hot ticket form (full load) 513 409 724 ms 578 ms
S3: Full history popup, hot ticket (full load) 1,277 29 286 ms 107 ms
S4: Ticket list with "Number of escalations" (full load) 635 60[...] [...] ms [...] ms
W1: Ticket create, update, purge (full cycle SQL, final page) 3,280 2,935 631 ms 676 ms
W2: Escalation via timeline form (full cycle SQL, final page) 3[...] [...] [...] ms [...] ms

Benchmark Analysis

  • Targeted Gains:
    • On S3, glpi_groups lookups drop from 1,250 to 5, and JavaScript console errors per render drop from 1,250 to 0.
    • On S2, total PHP requests drop from 12 to 9, improving DOMContentLoaded from 250 ms to 217 ms.
    • On S1, main-thread blocking by the plugin is completely eliminated (0 ms), with plugin lists rendering at 326 ms.
  • Statistical Significance: Performance improvements on S1, S2, S3, and S4 exceed measurement noise (min–max ranges before and after do not overlap). The S4 gain exceeds what the 3 removed queries alone account for, partially due to run-to-run variance in the list's dashboard calls.
  • Workflows (W1 & W2): Both workflows end on the ticket list (where the plugin executes no requests), and their execution times remain within measurement noise (overlapping min–max ranges).
  • Known Core Limitation: The "Number of escalations" search column retains its baseline overhead (3× to 4× slower search query than without the column), as this stems from GLPI core's COUNT/GROUP BY handling on history rows and requires a separate change.

@MyvTsv MyvTsv self-assigned this Nov 13, 2026
@MyvTsv
MyvTsv marked this pull request as ready for review November 13, 2026 10:52
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.

1 participant