Skip to content

Fix - Slow display of pages showing alerts when many alerts exist - #253

Draft
RomainLvr wants to merge 2 commits into
11.0/bugfixesfrom
fix/alerts-display-performance
Draft

RomainLvr wants to merge 2 commits into
11.0/bugfixesfrom
fix/alerts-display-performance

Conversation

@RomainLvr

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

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

Description

  • Here is a brief description of what this PR does

Pages that display alerts (ticket form, central page, ticket list) get slower as alerts accumulate, even when only a few of them are current. On a base with 50 000 alerts (100 current), the ticket form is ready about 480 ms later with the plugin than without it.

Causes:

  • Every alert renders its own inline <style> and <script>. The script reads and writes computed styles with jQuery, which forces a full style recalculation of the page per alert (22 ms per alert on a large ticket form).
  • PluginNewsAlert::findAllToNotify() filters on is_active, is_deleted and the dates, but no index covers them: MariaDB scans the whole alert table, twice per display (14 to 20 ms per query).
  • plugin_init_news() checks isInstalled() + isActivated(), which costs 4 queries on every HTTP request; the core only calls it for an active plugin.
  • PluginNewsAlert_Target::showForAlert() loads each target with one getFromDB().
  • PluginNewsAlert::post_updateItem() calls update() once per user who hid the alert.
  • news.js binds its delegated handlers again on every glpi.tab.loaded, so closing an alert sends one hide_alert.php request per tab loaded before.

Fix

  • Alert styling is plain CSS: the 60 % border opacity uses color-mix(), the full width on ITIL forms is a CSS rule in styles.css; the per-alert script and style are removed.
  • New index is_active_is_deleted_date_end on glpi_plugin_news_alerts, added by the migration (fresh install and update).
  • Remove the self-activation check from plugin_init_news().
  • Load target items with one query per itemtype in the Targets tab.
  • Reset hidden states with a single UPDATE on alert update.
  • Bind the JS handlers once, with namespaced events.

Performance impact

Measured on GLPI 11.0.13 (e2e environment, debug mode off), 50 000 alerts, 100 570 targets, 50 000 hidden states. Medians of 5 runs; SQL from the MariaDB log.

Element tested Before After Gain Without plugin
Ticket form: total blocking time (ms) 885 506 +43 % 446
Ticket form: fully loaded (ms) 2 259 1 861 +18 % 1 776
Central page: fully loaded (ms) 1 052 969 +8 % 922
Central page: total blocking time (ms) 51 0 +100 % 0
Alert lookup, SQL time per page (central page) (ms) 37.8 2.7 +93 % -
Alert lookup, SQL time per page (ticket form / ticket list) (ms) 28.6 / 28.1 1.7 / 1.6 +94 % -
Alert lookup, rows examined per page 100 170 370 +100 % -
SQL queries added by the plugin per HTTP request 6 2 +67 % -
Targets tab of an alert with 523 targets: SQL queries 561 36 +94 % -
Targets tab of an alert with 523 targets: server time (ms) 54 31 +43 % -
Closing an alert after 3 tab switches: hide_alert.php requests 4 1 +75 % -

Notes

  • The asset URLs only carry the plugin version: the next release must bump it, otherwise browsers keep the old news.js and styles.css in cache.
  • color-mix() requires Chrome 111, Firefox 113 or Safari 16.2.

@RomainLvr RomainLvr added the Performances Performance improvements label Nov 12, 2026
@RomainLvr RomainLvr self-assigned this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GLPI 11 Performances Performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant