Skip to content

fix(core): reduce SQL queries on forms, init and the tag Associated items tab - #404

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.

Description

Performance pass on the tag plugin, measured on a seeded e2e database (2,000 tickets, 2,000 computers, 1,000 tags, 50,238 tag links; hot items carrying 600 tags, one tag linked to 2,032 items).

Scenario SQL queries before after
Ticket form with 600 tags 1,633 978 (-40 %)
Computer form with 600 tags 1,406 783 (-44 %)
Tag "Associated items" tab (2,032 items) 3,224 166 (-95 %), rows examined 149,953 → 18,719
Ticket create/update/purge cycle 3,866 3,424 (-11 %)
Queries added by the plugin on every HTTP request 12 4 to 5 (core plugin-state lookups only)

Server time of the "Associated items" tab: 115 → 62 ms (significant over 5 runs). Other page timings are within run-to-run noise on a local database; the query reductions matter most on a remote database.

Changes

  • Init: no Plugin::isPluginActive() database lookups and no configuration read on every request (Plugin::getPlugins() with a fallback when no plugin is booted); the tags location is read only when a form can show tags.
  • Tag dropdown: the selected tags are read with one join query instead of one getFromDB() per tag; no query for new items; the available tags are memoized per search criteria for the request.
  • canItemtype(): the itemtypes of active tags are read once per request (reset on tag add/update/purge, migration, uninstall).
  • "Associated items" tab: no per-row item reload or entity name lookup; the entity is read from the selected rows; the type label is computed once per itemtype.
  • Schema: new plugin_tag_tags_id key on glpi_plugin_tag_tagitems (install and migration), used by every lookup by tag.
  • Entity tags endpoint: one join query instead of one query per tag; the session is released after the parameter check.
  • Saving tags: existing links read on one column; removed tags unlinked with one deleteByCriteria().
  • PluginTagTag::getSingleTag() was removed (no remaining caller).

Tests

  • New tests: tags field displayed once per item, entity of linked rules in the "Associated items" tab, massive-action field built from the selected items.
  • TagTestCase::setUp() resets the memoized values between tests.
  • PHPUnit suites green (49 tests); parallel-lint, PHPStan and php-cs-fixer clean.

Screenshots (if appropriate):

@MyvTsv MyvTsv self-assigned this Nov 13, 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.

1 participant