Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4589 Zobrazení

When should I use SQL Query or ORM Search Method to get better performance?
For instance:
Should I use this

query = """
        select distinct license_plate_number from car_car
        where state not in ('cancel', 'sold')
        and license_plate_number = '{}';
        """.format(license_plate_number)
self.env.cr.execute(query)
cars = self.env.cr.dictfetchall()
or this:
cars = self.search([
    ('license_plate_number', '=', self.license_plate_number),
    ('state', 'not in', ('cancel', 'sold'))
])


Avatar
Zrušit
Nejlepší odpověď

Hi,

Query is much faster than ORM. And when we use query we should take care as it bypass the orm layers, the security(rules and access rights) wont be considered. If it is small operation, go with orm layer, and for reporting and all use query.

Thanks & Regards

Avatar
Zrušit
Nejlepší odpověď

If you want to improve performance this might help you 

https://www.odoo.com/event/odoo-experience-2021-2847/track/performance-issues-here-are-the-best-solutions-4404 

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
led 25
1043
0
čvn 20
2723
2
srp 23
10515
0
čvc 25
826
1
čvc 25
674