Skip to content

Admin UI Listing Component Loads Data Twice #32998

Closed
@bentideswell

Description

@bentideswell

When using a listing component (eg. admin order grid), the initial browser request loads the collection for the grid with no filters or sorting applied. An AJAX request is then performed to reload the data with the correct sorting and filters.

I found this because I had a plugin that wrapped around getData for the oder grid data source and noticed that whenever I debugged the data, it was always the first 20 orders but the final page would display the 20 most recent orders because the default sorting was created_at DESC.

This first collection load (and all of the resulting queries) are pointless and a waste as the results are never displayed on screen and if they were, they would be incorrect. The collection loading via the Ajax call has the correct data.

Preconditions (*)

  1. I tested this on Magento 2.4.2. It may be present on older versions

Steps to reproduce

  1. Disable Javascript in your browser
  2. Enable DB query logging
  3. Visit the order grid
  4. Check the logs

At this point you should see the DB queries for the initial loading of the collection. This will load the collection with no filters or sorting. The results of this are not loaded on screen and the queries that come from this are a waste.

  1. Enable Javascript in your browser
  2. Delete the query log
  3. Visit the order grid
  4. Check the logs

Now you will see an extra set of queries for the actual data that ends up displaying on the page. This occurs via the AJAX request.

Expected result

When visiting the admin grid, I would expect no data to be loaded via the first request and the first queries to happen in the AJAX request.

Actual result (*)

The initial request loads the order collection with no filters or sorting and performs several follow up queries based on this data. This data (the first 20 orders) is never used and not displayed. An AJAX request is then performed to load the correct data.

I'm happy to fix this but I'm not sure of the best way.

In the site I'm working on, I've patched it by just checking for the isAjax parameter:

public function aroundGetData(DataProvider $subject, \Closure $callback)
{
    return $this->request->getParam('isAjax') ? $callback() : [];`
}

This check could be added in Magento\Ui\Component\Listing, but I don't know if this is the right way to fix it. A better way would be to only call Magento\Ui\Component\Listing::getDataSourceData() if it is actually needing to be used

If any one has any guidance on the best way to approach this, I am happy to look into a fix and provide a PR.


  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [*] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions