Skip to content
Snippets Groups Projects
Commit a658dfcd authored by Moises Lopez's avatar Moises Lopez
Browse files

[IMP] point_of_sale: Speed-up queries filtering by 'pos_order.state'

The following method:
 - https://github.com/odoo/odoo/blob/2091994c/addons/pos_restaurant/models/pos_config.py#L40

Gets the following query:

    SELECT min("pos_order".id) AS id,
    count("pos_order".id) AS "table_id_count",
    "pos_order"."table_id" as "table_id"
    FROM "pos_order"
    LEFT JOIN "restaurant_table" AS "pos_order__table_id" ON (
        "pos_order"."table_id" = "pos_order__table_id"."id")
    WHERE (("pos_order"."state" = 'draft')
        AND ("pos_order"."table_id" in (TOO MANY IDS HERE)))  -- for this case 178 restaurant_table records ids
    GROUP BY  "pos_order"."table_id", "pos_order__table_id"."id"
    ORDER BY "pos_order__table_id"."id"

It spends 24ms without index

After creating index it spends 0.57

It is not the unique side filtering by pos_order.state column

Check the following lines of code:
 - https://github.com/odoo/odoo/blob/f5553c550/addons/point_of_sale/models/pos_order.py#L678
 - https://github.com/odoo/odoo/blob/f5553c550/addons/point_of_sale/models/pos_order.py#L690
 - https://github.com/odoo/odoo/blob/f5553c550/addons/website_sale_coupon/models/sale_order.py#L91



closes odoo/odoo#129486

Signed-off-by: default avatarRémy Voet (ryv) <ryv@odoo.com>
parent 8cf5fb77
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment