Skip to content

Perf: read report configs once, rewrite heavy report queries - #411

Merged
jdurand-teclib merged 2 commits into
11.0/bugfixesfrom
perf/reports-queries
Dec 1, 2026
Merged

jdurand-teclib merged 2 commits into
11.0/bugfixesfrom
perf/reports-queries

Conversation

@Lainow

@Lainow Lainow commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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.

@Rom1-B
Rom1-B requested review from a team, Herafia, RomainLvr and jdurand-teclib and removed request for a team November 18, 2026 13:06
Herafia
Herafia previously approved these changes Nov 20, 2026
jdurand-teclib
jdurand-teclib previously approved these changes Nov 23, 2026
- getAllReports(): configs and profile rights loaded once per request
  instead of 4 queries per report (225 -> 7 plugin queries per page)
- Backlogs: cumulative opened/solved counts instead of a
  tickets x periods non-equi join, same series
- ComputersByOS: one GROUP BY on the OS name instead of 20 scans
- TicketNumberByService: type <> 1 instead of a NOT IN id list
- TicketStatusByTechnician: DISTINCT technician list
- ComputersByEntity: one grouped count instead of one per entity
- plugin_init: no activation check, rights counted not loaded
- ajax/common.tabs.php releases the session lock
Plugin::load() also runs plugin_init_mreporting() during plugin:install,
before the plugin tables exist.
@Lainow
Lainow dismissed stale reviews from jdurand-teclib and Herafia via 6814828 December 1, 2026 09:02
@Lainow
Lainow force-pushed the perf/reports-queries branch from 15f0acf to 6814828 Compare December 1, 2026 09:02
@jdurand-teclib
jdurand-teclib merged commit cc0b845 into 11.0/bugfixes Dec 1, 2026
7 checks passed
@jdurand-teclib
jdurand-teclib deleted the perf/reports-queries branch December 1, 2026 10:57
@glpi-project

glpi-project Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

Target Status
main ⚠️ Drafted with conflicts #416

Rom1-B added a commit that referenced this pull request Dec 4, 2026
## Checklist before requesting a review

*Please delete options that are not relevant.*

- [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

- It fixes #409
- On GLPI 12, the inventory reports showing percentages (by
manufacturer, type, status, printers by status) ended on the error page
because the total subquery lost its prepared statement values.
- The subquery values are now passed along with the percentage
expression.
- The remaining errors of #409 (union queries for computers by age and
by OS, empty IN on the SLA report) are fixed by the forward-ports of
#411 and #418.

```
Number of placeholders (6) in SQL statement does not match number of values (3).
```

## Screenshots (if appropriate):
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.

3 participants