Skip to content

Fix(core): performance batch filter_actors queries, slim rule form and rule save, clean links on purge - #124

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
  • 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.

Performance Optimizations & Benchmark

This update reduces the SQL overhead of the plugin, mainly on the "Assigned to" actor dropdown of the ticket form (filter_actors hook), on the rule form and on rule saves, and removes an unused asset loaded on every page.

Key Optimizations

Actor dropdown (filter_actors hook):

  • The level lookup for the groups already assigned to the ticket now runs as one query instead of one query per assigned group.
  • The entity visibility check of the groups allowed by the rule now runs as one glpi_groups query with id IN (...) instead of a countElementsInTableForEntity() plus a getFromDB() per group (the getFromDB() result was not used).
  • In the "all groups of the level" branch, the ids returned by getAllGroupForALevel() (already joined with glpi_groups and restricted to the entity) are used directly, without a getFromDB() per group.
  • The result of the hook is unchanged (full unpaginated response compared before and after on several tickets).

Rule form:

  • multipleDropdownGroup() and getSavedValues() load the 4 levels in one query each and keep the result for the render, instead of being called once per level (8 queries → 2).

Rule save:

  • post_updateItem() reads the current links once for all levels, then deletes only the links no longer selected and adds only the new ones, instead of deleting and re-adding every link (with its history line) on each save.

Rule purge:

  • Purging a rule now deletes its category-group links (cleanDBonPurge()); they were left behind and reappeared as preselected groups on a later rule for the same category.

Static JavaScript Assets:

  • Removed public/scripts/multiple_group.js and its ADD_JAVASCRIPT hook: it was loaded on every GLPI page while its only function (toggleSelect) is not used anywhere.

Database Changes

  • No schema change.
  • The install/update path removes existing orphan links (links whose rule no longer exists, rule id > 0), left by purges made before this change. It runs on existing installations on the next version bump.

Benchmark Results

Environment: GLPI 11.0.13, e2e database with 2,000 groups, 2,000 ITIL categories, 2,000 tickets, 1,980 rules and 50,000 category-group links (20 "hot" rules carry 25,000 links, 1,250 groups each; hot tickets have 20 assigned groups). Plugin active, debug mode and Xdebug disabled. Values are the median of 5 runs after a warm-up; SQL counts come from the MariaDB query log.

Scenario SQL (Before) SQL (After) Time (Before) Time (After)
S0: Central page, neutral (full load) 1,671 1,509 1,126 ms 1,097 ms
S1: Hot ticket form (full load) 1,484 1,390 1,272 ms 1,097 ms
S2: "Assigned to" dropdown, ajax/actors.php call 679 45 78.7 ms 57.1 ms
S2: Hot ticket + dropdown open (full load) 2,163 1,435 1,996 ms 1,915 ms
S3: Group form, plugin tab (full load) 171 167 261 ms 271 ms
S4: Rule list (full load) 99 97 242 ms 218 ms
S5: Hot rule form, 4 levels of 500 groups (full load) 138 128 371 ms 335 ms
W1: Rule create, save with 3 groups, purge (full cycle SQL, final page) 657 627 279 ms 285 ms
Rule save without change, 13 groups (POST request) 219 31 81 ms SQL 9 ms SQL

Note: the "After" SQL counts were measured with an extra change (removal of the Plugin::isPluginActive() check in plugin_init) that was reverted after review, because core also loads setup.php of inactive plugins (plugin list page, install, activate). Expect about one more query per HTTP request than shown (S0 +33, S1 +47, ajax/actors.php +1, W1 +11); the other gains are not affected.

Benchmark Analysis

Targeted Gains:

  • On S2, ajax/actors.php drops from 679 to 45 queries (34 without the plugin): the 307 glpi_groups getFromDB() + 307 entity counts + 20 level lookups are replaced by 2 queries. The plugin overhead on that call goes from +34 ms to +12 ms over core (44.9 ms without the plugin), and the query count no longer grows with the number of groups in the rule.
  • On S5, queries on plugin tables drop from 14 to 8.
  • Saving a rule without changes drops from 219 to 31 queries, with no more delete/re-add history lines for unchanged links.
  • W1 leaves no orphan link after a purge (3 per cycle before).
  • One resource less on every page (S0: 91 → 90).

Statistical Significance: the ajax/actors.php gain exceeds measurement noise (min–max ranges 72.6–101 ms before, 43.3–59.3 ms after). The S1 page also passes the range test, but the change only removes one cached JS file on that page, so it is mostly run-to-run variance (1,134 ms with the plugin inactive). S0, S3, S4, S5 and W1 times stay within measurement noise (overlapping ranges).

Known Limitation: saving a rule with about 1,000 selected groups or more fails with HTTP 403 before and after this change, because the POST exceeds PHP max_input_vars (1,000 by default); this is unrelated to the changes and needs a separate fix.

@MyvTsv MyvTsv self-assigned this Nov 13, 2026
@MyvTsv
MyvTsv marked this pull request as ready for review November 13, 2026 10:51
@Rom1-B
Rom1-B requested review from a team, Mary-Clb, RomainLvr and jdurand-teclib and removed request for a team November 18, 2026 15:07
jdurand-teclib
jdurand-teclib previously approved these changes Nov 23, 2026
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