Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin order list heavy query #14781

Closed
ulinskas opened this issue Feb 1, 2023 · 1 comment · Fixed by #15132
Closed

Admin order list heavy query #14781

ulinskas opened this issue Feb 1, 2023 · 1 comment · Fixed by #15132

Comments

@ulinskas
Copy link
Contributor

ulinskas commented Feb 1, 2023

Sylius version affected: 1.12.1

Description
When sylius admin orders page fetch orders, it joins unnecessary tables which makes query larger, heavier and longer.

Steps to reproduce
Visit /admin/orders/ page and check query created via doctrine.

  1. For counting orders it selects all unnecessary order data + joins order items, products and product variants. This query requires only order id count and order state.
  2. Displaying paginated order list. Same problem, fetches too much data + joins products and product variants.

Possible Solution
Changes must be made here:
/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php

From:

    public function createSearchListQueryBuilder(): QueryBuilder
    {
        return $this->createListQueryBuilder()
            ->leftJoin('o.items', 'item')
            ->leftJoin('item.variant', 'variant')
            ->leftJoin('variant.product', 'product')
        ;
    }

To:

    public function createSearchListQueryBuilder(?array $criteria = []): QueryBuilder
    {
        $builder = $this->createListQueryBuilder();

        $hasProductCriteria = $criteria['product'] ?? false;
        $hasVariantCriteria = $criteria['variant'] ?? false;

        if ($hasProductCriteria || $hasVariantCriteria) {
            $builder
                ->leftJoin('o.items', 'item')
                ->leftJoin('item.variant', 'variant')
                ->leftJoin('variant.product', 'product');
        }

        return $builder;
    }
@Rafikooo
Copy link
Contributor

Hello,

Thank you for raising this issue. You're right about this case.

We appreciate your engagement with the Sylius community, and we encourage you to open a pull request with your suggested changes to the code. This will allow us to review the changes and potentially merge them into the codebase 💃

Thank you again for your contribution to Sylius, and please let us know if you have any further questions or concerns 🚀

Best regards,
Rafał

GSadee added a commit that referenced this issue Jul 4, 2023
…lly (jakubtobiasz)

This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13
| Bug fix?        | no/
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | closes #14781
| License         | MIT


Commits
-------

84738dd Add joins on the orders list conditionally
6bb765d Fix broken displaying customer's orders in the admin panel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants