Merge lp:~florent.x/openerp-client-lib/trunk-imp01 into lp:openerp-client-lib

Proposed by Florent
Status: Rejected
Rejected by: Nicolas Vanhoren (OpenERP)
Proposed branch: lp:~florent.x/openerp-client-lib/trunk-imp01
Merge into: lp:openerp-client-lib
Diff against target: 19 lines (+3/-6)
1 file modified
openerplib/main.py (+3/-6)
To merge this branch: bzr merge lp:~florent.x/openerp-client-lib/trunk-imp01
Reviewer Review Type Date Requested Status
Nicolas Vanhoren (OpenERP) Disapprove
Review via email: mp+89217@code.launchpad.net

Description of the change

More efficient Model.__getattr__.

To post a comment you must log in.
Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

It's not that it's bad, but your code does not bring anything. It does not solve any bug, it does not have a better complexity,... it's just a little bit different but does exactly the same.

But I don't want to replace a well-tested code by something else that is exactly the same except it is not well-tested, so I have to refuse.

review: Disapprove
Revision history for this message
Florent (florent.x) wrote :

I agree the alternative dict() construct does not bring any perf benefit.

Maybe you want to do only the two simple changes:
 - merge the 2 "if" in a single condition
 - replace expression "if len(result) > 0" with "if result"

Unmerged revisions

46. By Florent

[imp] improve Model.__getattr__.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerplib/main.py'
2--- openerplib/main.py 2012-01-09 09:19:06 +0000
3+++ openerplib/main.py 2012-01-19 10:37:25 +0000
4@@ -248,12 +248,9 @@
5 self.model_name,
6 method,
7 args, kw)
8- if method == "read":
9- if isinstance(result, list) and len(result) > 0 and "id" in result[0]:
10- index = {}
11- for r in result:
12- index[r['id']] = r
13- result = [index[x] for x in args[0] if x in index]
14+ if method == 'read' and result and isinstance(result, list) and 'id' in result[0]:
15+ index = dict((r['id'], r) for r in result)
16+ result = [index[rid] for rid in args[0] if rid in index]
17 self.__logger.debug('result: %r', result)
18 return result
19 return proxy

Subscribers

People subscribed via source and target branches