Track Usage module creates too many database queries
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3535772. --> Reported by: [alorenc](https://www.drupal.org/user/3603980) Related to !9 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>The track_usage module is creating way too many database queries when users edit content. This makes the site very slow.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>Move the usages recording at the end, just before the response is sent back. In this way we can collect all queries and remove duplicate queries. <ul> <li>Make <code>Recorder</code> service also an event subscriber</li> <li>Add the <code>Recorder::registerUsageRecords()</code> that subscribes to <code>KernelEvents::RESPONSE</code></li> <li>The <code>Recorder::record()</code> method will only collect source &amp; traversable entities and will schedule them to be processed in <code>Recorder::registerUsageRecords()</code></li> </ul> </li> <li>Avoid one query for each traversable update/delete. Collect them separately and perform a single query</li> </ul>
issue