Skip to content

[Perf] Reduce SQL queries and page weight added by the plugin - #54

Open
RomainLvr wants to merge 3 commits into
11.0/bugfixesfrom
fix/jamf-performance-improvements
Open

RomainLvr wants to merge 3 commits into
11.0/bugfixesfrom
fix/jamf-performance-improvements

Conversation

@RomainLvr

@RomainLvr RomainLvr commented Nov 12, 2026 •

Copy link
Copy Markdown

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.
  • This change requires a documentation update.

Description

  • Here is a brief description of what this PR does

A benchmark on a seeded database (4 000 assets, 3 900 Jamf devices, 50 000 extension attribute values, 50 000 pending imports) showed several avoidable costs added by the plugin to every GLPI request and to its own pages. It also showed a crash on the main tab of Jamf-linked assets when Twig strict variables are enabled (dev and test environments):

Key "url" for sequence/mapping with keys "caption, on_click" does not exist in "@jamf/inventory_info.html.twig" at line 43.

Fix

  • setup.php: remove the Plugin::isPluginActive('jamf') check from plugin_init_jamf(). GLPI already calls the init only for active plugins, and the check read glpi_plugins twice on every HTTP request, AJAX calls included.
  • inc/migration.class.php: add an index on glpi_plugin_jamf_mobiledevices.glpi_plugin_jamf_devices_id in the 3.2.4 migration. The join done on every Phone form scanned the whole table.
  • front/merge.php / merge.html.twig: hide the already linked items with a dropdown condition (subquery) instead of an inline used list of every linked id in each row. The page no longer reads the whole devices table.
  • inc/abstractdevice.class.php: cache getJamfItemClassForGLPIItem() per request (it runs once per tab name and once for the information block). The cache entry is cleared when the item is purged.
  • inc/connection.class.php: add a connect timeout (5 s) and a total timeout (30 s) to the Jamf API calls (Guzzle client and token requests). The MDM commands tab calls the API while it renders, and a slow Jamf server could block the page and the PHP worker.
  • js/jamf.js is now loaded only by the MDM commands tab instead of every GLPI page.
  • inventory_info.html.twig: test button.url is defined to fix the crash above.

Results

Measure Before After
SQL queries per HTTP request added by the plugin init 2 0
Phone form, rows examined 8 355 4 352
Computer write cycle (14 requests), SQL queries 1 090 1 059
Merge page HTML 523 KB 355 KB
Plugin scripts loaded on every page 1 0

Display times did not change significantly at these volumes. The gains grow with the size of the fleet.

Notes

  • The MDM commands tab could not be tested without a Jamf server.

@RomainLvr RomainLvr added the Performance Performance improvement label Nov 12, 2026
@RomainLvr RomainLvr self-assigned this Nov 12, 2026
@RomainLvr
RomainLvr marked this pull request as ready for review November 25, 2026 10:57
@RomainLvr
RomainLvr requested review from a team, Herafia, Rom1-B and jdurand-teclib and removed request for a team November 25, 2026 10:57
@RomainLvr RomainLvr changed the title Fix - Reduce SQL queries and page weight added by the plugin [Perf] Reduce SQL queries and page weight added by the plugin Nov 25, 2026

@jdurand-teclib jdurand-teclib left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#55 has some changes that might be in conflict with those made here (See reviews)
See suggestions to avoid issues after the rebase.

It might be worth making a functionnal check after rebasing and solving the conflicts to ensure everything is ok, tho.

Comment thread setup.php
$PLUGIN_HOOKS['csrf_compliant']['jamf'] = true;

if (Plugin::isPluginActive('jamf')) {
$PLUGIN_HOOKS['add_javascript']['jamf'][] = 'js/jamf.js';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#55 Makes js/jamf.js holding all click handlers. Suppressing this hook might disable buttons effects all over the plugin, once the changes will be rebased.

Comment thread CHANGELOG.md

- Fix `migration:unsigned_keys` failure on `glpi_plugin_jamf_devices.jamf_items_id` (negative default value)
- Fix main tab of Jamf-linked computers and phones crashing when Twig strict variables are enabled
- Fix SQL queries and page weight added by the plugin: no plugin state check on every request, index on mobile devices, lighter merge page, `jamf.js` only loaded on the MDM commands tab

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you restore the ADD_JAVASCRIPT hook, this statement is not true anymore.

Suggested change
- Fix SQL queries and page weight added by the plugin: no plugin state check on every request, index on mobile devices, lighter merge page, `jamf.js` only loaded on the MDM commands tab
- Fix SQL queries and page weight added by the plugin: no plugin state check on every request, index on mobile devices, lighter merge page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GLPI 11 Performance Performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants