تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4451 أدوات العرض

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


الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
أفضل إجابة

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 

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يناير 25
958
0
يونيو 20
2648
2
أغسطس 23
10437
1
يوليو 25
248
0
فبراير 25
1118