Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
4400 Vizualizări

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'))
])


Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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 

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
ian. 25
908
0
iun. 20
2622
2
aug. 23
10403
0
iul. 25
29
0
feb. 25
1087