From 3d3bc0477134e80002da7732911492d0984e418f Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Sun, 27 Jun 2010 23:00:16 +0300 Subject: [PATCH] ir.attachment: Index on res_model,res_id _All_ client forms are trying to locate attachments of records, so they are querying ir.attachment for their (res_model, res_id). Speed that up! bzr revid: p_christ@hol.gr-20100627200016-gt9cyafm97if51e5 --- bin/addons/base/ir/ir_attachment.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/addons/base/ir/ir_attachment.py b/bin/addons/base/ir/ir_attachment.py index 121b6a3de37..abba9222d25 100644 --- a/bin/addons/base/ir/ir_attachment.py +++ b/bin/addons/base/ir/ir_attachment.py @@ -124,6 +124,13 @@ class ir_attachment(osv.osv): 'type': 'binary', } + def _auto_init(self, cr, context=None): + super(ir_attachment, self)._auto_init(cr, context) + cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_attachment_res_idx',)) + if not cr.fetchone(): + cr.execute('CREATE INDEX ir_attachment_res_idx ON ir_attachment (res_model, res_id)') + cr.commit() + ir_attachment()