Merge lp:~openerp-dev/openobject-server/7.0-opw-592482-rha into lp:openobject-server/7.0

Proposed by Rifakat Husen (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-server/7.0-opw-592482-rha
Merge into: lp:openobject-server/7.0
Diff against target: 24 lines (+3/-2)
1 file modified
openerp/addons/base/res/res_company.py (+3/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-server/7.0-opw-592482-rha
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp (community) Approve
Naresh(OpenERP) Pending
Review via email: mp+167466@code.launchpad.net

Description of the change

Replaced browse return user.company_id.id by read() in _company_default_get() of res_company.
This causes performance issue as browse call will read all the fields' value for company, partner and user and specifically when a big image uploaded for any user.

_company_default_get() is widely used in _defaults to get default company of the user. read() of the user's company
will not going to read all the fields and save time.

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

That's an acceptable mitigation of the performance penalty inflicted by large binary (image) on a user for the stable version. A better solution for the trunk is to not pre-fetch the binary files in the browse_records.
The browse_record will be fetched (so with the image) only if a rule needs to consume it. Otherwise, only a read on the company_id will be done. -> Probably most of the cases won't read the binary.

More details in the discussion of the bug report: https://bugs.launchpad.net/openobject-server/+bug/1177965

Thanks

review: Approve
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

The patch itself looks fine, but it might indeed not be necessary now that the behavior of browse_record prefetching was fixed to never prefetch images. See also revision 5014 rev-id: <email address hidden> in 7.0.

Unmerged revisions

4998. By Guewen Baconnier @ Camptocamp <email address hidden>

[FIX] res_comapy: prevent browse of user.company_id by read() in _company_default_get(),
this can cause performance issue as browse call will read all the m2o filds for company, partner and user and specificallly an big image and that
kills performance

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/res/res_company.py'
2--- openerp/addons/base/res/res_company.py 2013-05-31 07:47:45 +0000
3+++ openerp/addons/base/res/res_company.py 2013-06-05 07:09:45 +0000
4@@ -203,17 +203,18 @@
5 if not context:
6 context = {}
7 proxy = self.pool.get('multi_company.default')
8+ user_obj = self.pool.get('res.users')
9 args = [
10 ('object_id.model', '=', object),
11 ('field_id', '=', field),
12 ]
13
14 ids = proxy.search(cr, uid, args, context=context)
15- user = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
16+ user = user_obj.browse(cr, SUPERUSER_ID, uid, context=context)
17 for rule in proxy.browse(cr, uid, ids, context):
18 if eval(rule.expression, {'context': context, 'user': user}):
19 return rule.company_dest_id.id
20- return user.company_id.id
21+ return user_obj.read(cr, SUPERUSER_ID, uid, ['company_id'], context=context)['company_id'][0]
22
23 @tools.ormcache()
24 def _get_company_children(self, cr, uid=None, company=None):