ir.attachment: Index on res_model,res_id
authorP. Christeas <p_christ@hol.gr>
Sun, 27 Jun 2010 20:00:16 +0000 (23:00 +0300)
committerP. Christeas <p_christ@hol.gr>
Sun, 27 Jun 2010 20:00:16 +0000 (23:00 +0300)
_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

index 121b6a3..abba922 100644 (file)
@@ -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()