From a830b08f052c77ce75d9823af98b511364a7e07c Mon Sep 17 00:00:00 2001 From: Soban Javed Date: Thu, 7 Oct 2021 16:06:58 +0500 Subject: [PATCH] refactor: use value for filtering indexed boolean field --- openedx/core/djangoapps/user_api/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/user_api/models.py b/openedx/core/djangoapps/user_api/models.py index 605f22c6b1..d9f91fe3e7 100644 --- a/openedx/core/djangoapps/user_api/models.py +++ b/openedx/core/djangoapps/user_api/models.py @@ -199,11 +199,15 @@ class RetirementState(models.Model): @classmethod def get_dead_end_states(cls): - return cls.objects.filter(is_dead_end_state=True) + # We use models.Value(1) to make use of the indexing on the field. MySQL does not + # support boolean types natively, and checking for False will cause a table scan. + return cls.objects.filter(is_dead_end_state=models.Value(1)) @classmethod def get_dead_end_state_names_list(cls): - return cls.objects.filter(is_dead_end_state=True).values_list('state_name', flat=True) + # We use models.Value(0) to make use of the indexing on the field. MySQL does not + # support boolean types natively, and checking for False will cause a table scan. + return cls.objects.filter(is_dead_end_state=models.Value(1)).values_list('state_name', flat=True) @classmethod def get_state_names_list(cls):