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
1=== modified file 'product_price_history/product_price_history.py'
2--- product_price_history/product_price_history.py 2014-02-04 10:46:08 +0000
3+++ product_price_history/product_price_history.py 2014-04-03 11:22:08 +0000
4@@ -33,10 +33,21 @@
5
6
7 class product_price_history(orm.Model):
8- # TODO : Create good index for select
9 _name = 'product.price.history'
10 _order = 'datetime, company_id asc'
11
12+ def _auto_init(self, cr, context=None):
13+ res = super(product_price_history, self)._auto_init(cr,
14+ context=context)
15+ cr.execute("SELECT indexname "
16+ "FROM pg_indexes "
17+ "WHERE indexname = 'product_price_history_all_index'")
18+ if not cr.fetchone():
19+ cr.execute("CREATE INDEX product_price_history_all_index "
20+ "ON product_price_history "
21+ "(product_id, company_id, name, datetime)")
22+ return res
23+
24 _columns = {
25 'name': fields.char('Field name', size=32, required=True),
26 'company_id': fields.many2one('res.company', 'Company',

Subscribers

People subscribed via source and target branches