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

[IMP] pos_coupon: Speed-up computing domain for products and partners #164771

Closed
wants to merge 1 commit into from

Conversation

moylop260
Copy link
Contributor

@moylop260 moylop260 commented May 7, 2024

  • Re-using results for domains duplicated
  • Ordering by id instead of default heavy unused order

Opening a POS sessions our SQL profiler shows the following query executed too many times:

  • Screenshot 2024-05-07 at 8 41 09 a m

Checking the PY profilers the following method is reported as slow:

program.valid_partner_ids = self.env["res.partner"].search(domain).ids

  • Screenshot 2024-05-07 at 8 42 17 a m

The reason it is executing the same query too many times with the same domain

So, I have created this change to re-use the result if the domain is repeated

Also, the query generated has heavy order by

order by "res_partner"."type", coalesce("res_partner"."is_company", false) desc, "res_partner"."display_name", "res_partner"."id";

Replacing by order by "res_partner"."id" it is faster

Before Execution Time: 104.256 ms
Now Execution Time: 31.802 ms

So, it is ~4x faster for each query and it is re-using data for the same query using a LRU-Cache locally in the method

@robodoo
Copy link
Contributor

robodoo commented May 7, 2024

Pull request status dashboard.

@moylop260
Copy link
Contributor Author

@caburj What do you think?

Copy link
Contributor

@adgu-odoo adgu-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good but can you take a look at my comments ?

addons/pos_coupon/models/coupon_program.py Show resolved Hide resolved
addons/pos_coupon/models/coupon_program.py Show resolved Hide resolved
@moylop260 moylop260 force-pushed the 15.0-speedup-coupon-odoo-moy branch from f94d0f7 to 4b73999 Compare May 8, 2024 14:33
@moylop260 moylop260 changed the title [REF] pos_coupon: Speed-up computing domain for products and partners [IMP] pos_coupon: Speed-up computing domain for products and partners May 8, 2024
@moylop260 moylop260 force-pushed the 15.0-speedup-coupon-odoo-moy branch from 4b73999 to 5e5e638 Compare May 8, 2024 15:17
@hugho-ad
Copy link
Contributor

LGTM 👍

@moylop260
Copy link
Contributor Author

@adgu-odoo Could you review it, please?

Copy link
Contributor

@carlosdauden carlosdauden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adgu-odoo
Copy link
Contributor

You can revert what I said about literal_eval and then ping me when the runbot is green

- Re-using result for domains duplicated
- Ordering by id instead of default heavy unused order
@moylop260 moylop260 force-pushed the 15.0-speedup-coupon-odoo-moy branch from 5e5e638 to bfb97ef Compare May 22, 2024 14:04
@moylop260
Copy link
Contributor Author

@adgu-odoo

Thank you for reply!

I have created the changes requested and the runbot CI is green now

@adgu-odoo
Copy link
Contributor

@robodoo r+

robodoo pushed a commit that referenced this pull request May 23, 2024
- Re-using result for domains duplicated
- Ordering by id instead of default heavy unused order

closes #164771

Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com>
@robodoo robodoo closed this May 23, 2024
@fw-bot
Copy link
Contributor

fw-bot commented May 27, 2024

@moylop260 @adgu-odoo this pull request has forward-port PRs awaiting action (not merged or closed):

2 similar comments
@fw-bot
Copy link
Contributor

fw-bot commented May 28, 2024

@moylop260 @adgu-odoo this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented May 29, 2024

@moylop260 @adgu-odoo this pull request has forward-port PRs awaiting action (not merged or closed):

@moylop260
Copy link
Contributor Author

@adgu-odoo

I have created the following FW PR manually:

#166608

@moylop260 moylop260 deleted the 15.0-speedup-coupon-odoo-moy branch May 29, 2024 11:25
@fw-bot
Copy link
Contributor

fw-bot commented May 30, 2024

@moylop260 @adgu-odoo this pull request has forward-port PRs awaiting action (not merged or closed):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants