Repository navigation
Fix(Perf): remove per-row SQL queries from voucher views and the init activation check - #280
Open
jdurand-teclib wants to merge 1 commit into
Open
jdurand-teclib wants to merge 1 commit into
jdurand-teclib wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The fix removes the queries that the Credit plugin ran once per row in its three list views. The consumed details of a busy voucher drop from 17,532 to 262 SQL queries, and its server time from 978 ms to 251 ms. Each GLPI request also runs 2 fewer queries. The rendered output does not change: the HTML of the ticket tab, the entity tab and the consumed details is identical between the two versions, once random ids and CSRF tokens are masked.
Three configurations were tested on the same instance, with the same data: plugin disabled (core cost only, for the core pages), before (
mainbranch, 1.15.8) and after (fix).SQL Queries
The three plugin views no longer depend on the number of rows: the remaining queries are the GLPI page itself, plus one user lookup per distinct user.
glpi_pluginsqueries per HTTP requestBefore the fix,
displayConsumed()loaded the ticket, its category and its user for each consumption: 3 queries per row. It now reads tickets and categories with the consumptions in oneLEFT JOINquery, and builds each user link once per user.showForTicket()read the voucher and the user of each row. Then it calledPluginCreditEntity::showForItemtype($entity, 'Ticket'), which computed every active voucher of the entity (link, type, two consumption sums and an iframe modal each) and displayed nothing, because the template is only rendered for an Entity. The call is removed, and voucher names are loaded in oneINquery.showForItemtype()re-read each voucher withgetById()although the row was already fetched, read its type, and summed its consumptions twice. It now reuses the row, caches the type links, and gets all the sums from oneGROUP BYquery (getConsumedForCredits()).plugin_init_credit()checked$plugin->isActivated('credit'). During init this callsgetFromDBbyDir(), which costs 2 queries on every request. The core only initializes active plugins, so the check is removed. The 2 remaining extraglpi_pluginsqueries per request belong to the core's own load of an active plugin.Response Times
The consumed details and the ticket tab are clearly faster. The other changes stay within the noise of a local database.
The test database runs on the same machine, so a query costs about 0.1 to 0.5 ms. With a remote database, the gain depends on network latency: at 0.5 ms per round trip, the 17,270 queries saved on the consumed details would save about 8.6 s. This is an estimate, not a measurement.
Two browser costs are unchanged because they need an interface change: the ticket tab still renders all rows (4.3 MB of HTML for 1,263 consumptions), and the entity tab still builds one hidden iframe modal per voucher (1 MB for 100 vouchers).
Other changes
glpi_plugin_credit_ticketconfigs) through anitem_purgehook. Before, each purge left an orphan row. Consumptions are kept, because they still count against their voucher.displayConsumed()no longer passes thecommentsoption toITILCategory::getName(). GLPI 11 ignores this option and raised anE_USER_WARNINGon every row with a category.