Skip to content

[main] Perf: read report configs once, rewrite heavy report queries - #416

Draft
glpi-project[bot] wants to merge 1 commit into
mainfrom
forward-port/411-to-main
Draft

glpi-project[bot] wants to merge 1 commit into
mainfrom
forward-port/411-to-main

Conversation

@glpi-project

@glpi-project glpi-project Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Forward-port of #411 to main.

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.

Description

Every report page loaded the configuration and the right of each of the 53 reports, 4 queries per report, several times per page. A few reports also ran queries whose cost grew with the ticket volume.

  • Report configs and rights (getAllReports(), initConfigParams(), canViewReports()): loaded once per request and cached. The cache is reset when a config or a right is added, updated or purged.
  • Backlogs: the old query built a list of period ends from every ticket, then joined every ticket to every period (date <= period AND solvedate > period).
    • It now counts opened and solved tickets per period and accumulates them in PHP.
    • The displayed periods are unchanged.
    • The actor joins are only added when their filter is set.
  • ComputersByOS: replaced a union of 10 branches, each with a total subquery (20 scans), by one GROUP BY on the OS name. The families are matched in PHP with the same regexps, case-insensitive.
  • TicketNumberByService: NOT type = 1 instead of loading every incident id and sending them back in a NOT IN list. type is NOT NULL, so the result is the same.
  • TicketStatusByTechnician: the technician list uses DISTINCT (it returned one row per assignment).
  • ComputersByEntity: one count grouped by entity instead of one count per entity.
  • plugin_init: removed the Plugin::isPluginActive() check, and the profile rights are counted instead of loaded.
  • ajax/common.tabs.php: releases the session lock after its checks.

Same results

I compared the chart data (datas, labels, links) between the old and the new code, using a SHA-256 of each chart. All 19 cases are identical:

  • Backlogs by day, week, month and year;
  • Backlogs filtered by technician, group, leaf category and root category;
  • TicketStatusByTechnician, TicketNumberByService, ComputersByOS, ComputersByEntity and TicketNumberByEntity;
  • the report dropdown, the statistics entries and the central tab.

Benchmark

Benchmark setup:

  • GLPI 11.0/bugfixes, e2e database, debug mode and Xdebug off;
  • 50 000 tickets over two years, with actors, groups, categories and SLAs;
  • 2 000 users, groups, categories and computers, 200 entities;
  • a dashboard of 8 widgets;
  • reports with their default selectors (365 days);
  • 5 runs per scenario after a warm-up, medians reported;
  • SQL counted from the MariaDB query log.
Scenario SQL queries before SQL queries after Server time before Server time after
Plugin dashboard, 8 widgets 672 176 (-74 %) 1 025 ms 671 ms (-35 %)
Central dashboard tab, iframe 395 107 (-73 %) 1 017 ms 631 ms (-38 %)
Report Backlogs 327 (491 ms SQL) 109 (276 ms SQL) 551 ms 342 ms (-38 %)
Report ComputersByOS 324 (89 ms SQL) 104 (18 ms SQL) 162 ms 88 ms (-46 %)
Report TicketNumberByService 327 (124 ms SQL) 105 (82 ms SQL) 185 ms 122 ms (-34 %)
Report TicketStatusByTechnician 323 (173 ms SQL) 103 (133 ms SQL) 257 ms 193 ms (-25 %)
Report ComputersByEntity 556 110 (-80 %) 121 ms 93 ms (not significant)
Any report page, queries on plugin tables 225 7 (-97 %)
Core statistics page (91 without the plugin) 305 97 (-68 %) 84 ms 86 ms (not significant)
Neutral core page (96 without the plugin) 102 100 128 ms 96 ms (not significant)

What remains:

  • each dashboard still renders its 8 reports in one request (about 600 ms of SQL);
  • GroupChange takes about 100 ms;
  • the protovis charts block the browser for 470 to 640 ms.

@glpi-project

glpi-project Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin forward-port/411-to-main
git worktree add --checkout .worktree/forward-port/411-to-main forward-port/411-to-main
cd .worktree/forward-port/411-to-main
git reset --hard HEAD^
git cherry-pick -x cc0b8456ceed03cf5f28a7929da6eaf0071efbf6

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