[FIX] survey*: add missing index FKs for performance

1) `survey_user_input.slide_partner_id`: this is a sparse column (so using
`btree_not_null` means a very small footprint). But it makes a ton of
difference when trying to delete a slide.slide.partner entry.
e.g. on a db with 500k survey inputs, the deletion of 1000
`slide.slide.partner` records goes from 40s to 100ms (400x speedup)

2) `survey_user_input_line.survey_id`: this is the inverse field of the
`survey_user_input.user_input_line_ids` O2M field, so the index is
always useful to retrieve the O2M lines. It will also marginally help
for cascading the deletion of any `survey_user_input` record from
case 1).

closes odoo/odoo#116875

X-original-commit: 2dc929cd530ba4fd80c17f91af2bfad02a819dd6
Signed-off-by: Olivier Dony (odo) <odo@odoo.com>
This commit is contained in:
Olivier Dony
2023-03-29 23:37:17 +02:00
parent 2d238a9981
commit 3e5880236e
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -614,7 +614,7 @@ class SurveyUserInputLine(models.Model):
_order = 'question_sequence, id'
# survey data
user_input_id = fields.Many2one('survey.user_input', string='User Input', ondelete='cascade', required=True)
user_input_id = fields.Many2one('survey.user_input', string='User Input', ondelete='cascade', required=True, index=True)
survey_id = fields.Many2one(related='user_input_id.survey_id', string='Survey', store=True, readonly=False)
question_id = fields.Many2one('survey.question', string='Question', ondelete='cascade', required=True)
page_id = fields.Many2one(related='question_id.page_id', string="Section", readonly=False)
@@ -11,7 +11,8 @@ class SurveyUserInput(models.Model):
slide_id = fields.Many2one('slide.slide', 'Related course slide',
help="The related course slide when there is no membership information")
slide_partner_id = fields.Many2one('slide.slide.partner', 'Subscriber information',
help="Slide membership information for the logged in user")
help="Slide membership information for the logged in user",
index='btree_not_null') # index useful for deletions in comodel
@api.model_create_multi
def create(self, vals_list):