Merge lp:~camptocamp/margin-analysis/7.0-product_price_history-index-1301847 into lp:~margin-analysis-core-editors/margin-analysis/7.0

Proposed by Guewen Baconnier @ Camptocamp
Status: Merged
Merged at revision: 63
Proposed branch: lp:~camptocamp/margin-analysis/7.0-product_price_history-index-1301847
Merge into: lp:~margin-analysis-core-editors/margin-analysis/7.0
Diff against target: 26 lines (+12/-1)
1 file modified
product_price_history/product_price_history.py (+12/-1)
To merge this branch: bzr merge lp:~camptocamp/margin-analysis/7.0-product_price_history-index-1301847
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no test Approve
Pedro Manuel Baeza code review Approve
Review via email: mp+214001@code.launchpad.net

Commit message

Add index on the columns that are used in the SELECT everytime a price is fetched

Description of the change

fix lp:1301847

Details on the bug report.
That also removes a TODO!

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Can't this be done with select=1 attribute?

Regards.

review: Needs Information (code review)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

No, we can't do composed indexes with select=True

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Ah, OK, the intention is to compose a full index of the four fields. I get it.

Regards.

review: Approve (code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Good catch

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'product_price_history/product_price_history.py'
--- product_price_history/product_price_history.py 2014-02-04 10:46:08 +0000
+++ product_price_history/product_price_history.py 2014-04-03 11:22:08 +0000
@@ -33,10 +33,21 @@
3333
3434
35class product_price_history(orm.Model):35class product_price_history(orm.Model):
36 # TODO : Create good index for select
37 _name = 'product.price.history'36 _name = 'product.price.history'
38 _order = 'datetime, company_id asc'37 _order = 'datetime, company_id asc'
3938
39 def _auto_init(self, cr, context=None):
40 res = super(product_price_history, self)._auto_init(cr,
41 context=context)
42 cr.execute("SELECT indexname "
43 "FROM pg_indexes "
44 "WHERE indexname = 'product_price_history_all_index'")
45 if not cr.fetchone():
46 cr.execute("CREATE INDEX product_price_history_all_index "
47 "ON product_price_history "
48 "(product_id, company_id, name, datetime)")
49 return res
50
40 _columns = {51 _columns = {
41 'name': fields.char('Field name', size=32, required=True),52 'name': fields.char('Field name', size=32, required=True),
42 'company_id': fields.many2one('res.company', 'Company',53 'company_id': fields.many2one('res.company', 'Company',

Subscribers

People subscribed via source and target branches