[FIX] web_editor: add index on original_id to improve delete performance
In #45174, the original_id field was added on ir.attachment, so that derived images in the web-editor (cropped, resized, optimized, ...) could keep a trace of the original, such that if the user wanted to revert it or change the crop/size/optimization parameter, we could do it from the original again so that for example the quality can be increased or the crop region made bigger. The addition of this self-referencing many2one from ir.attachment to itself however will cause DELETE queries on ir.attachment to do a sequential scan on the table to update potential records referencing the deleted record in their original_id field. As the ir.attachment table tends to be one of the biggest tables in production databases (millions of records), this scan can take multiple seconds per DELETE operation, and since attachments are used everywhere in odoo to represent files, DELETE operations on them are frequent. Adding an index on the original_id field should make these DELETE operations substantially faster (scaling with the log of the number of filled original_id fields, which will be very small, instead of scaling linearly with number of records) closes odoo/odoo#54676 X-original-commit: 2b5064a00b7a5c8dc66429869287386f244b1257 Signed-off-by: Olivier Dony (odo) <odo@openerp.com> Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -14,7 +14,7 @@ class IrAttachment(models.Model):
|
||||
image_src = fields.Char(compute='_compute_image_src')
|
||||
image_width = fields.Integer(compute='_compute_image_size')
|
||||
image_height = fields.Integer(compute='_compute_image_size')
|
||||
original_id = fields.Many2one('ir.attachment', string="Original (unoptimized, unresized) attachment")
|
||||
original_id = fields.Many2one('ir.attachment', string="Original (unoptimized, unresized) attachment", index=True)
|
||||
|
||||
def _compute_local_url(self):
|
||||
for attachment in self:
|
||||
|
||||
Reference in New Issue
Block a user