Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: utilisation d'une annotation pour éviter des requêtes en boucle #4878

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ def with_accepted_at(self):
)
)

def with_jobseeker_eligibility_diagnosis(self):
def with_jobseeker_valid_eligibility_diagnosis(self):
"""
Gives the "eligibility_diagnosis" linked to the job application or if none is found
the last valid eligibility diagnosis for this job seeker and this SIAE
Gives the last valid eligibility diagnosis for this job seeker and this SIAE
"""
sub_query = Subquery(
(
Expand All @@ -240,7 +239,18 @@ def with_jobseeker_eligibility_diagnosis(self):
),
output_field=models.IntegerField(),
)
return self.annotate(jobseeker_eligibility_diagnosis=Coalesce(F("eligibility_diagnosis"), sub_query, None))
return self.annotate(jobseeker_valid_eligibility_diagnosis=sub_query)

def with_jobseeker_eligibility_diagnosis(self):
"""
Gives the "eligibility_diagnosis" linked to the job application or if none is found
the last valid eligibility diagnosis for this job seeker and this SIAE
"""
return self.with_jobseeker_valid_eligibility_diagnosis().annotate(
jobseeker_eligibility_diagnosis=Coalesce(
F("eligibility_diagnosis"), F("jobseeker_valid_eligibility_diagnosis")
)
)

def eligibility_validated(self):
return self.filter(
Expand Down
2 changes: 1 addition & 1 deletion itou/templates/apply/includes/list_card_body_company.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3>
PASS IAE {{ approval.get_state_display|lower }}
</span>
{% else %}
{% if job_application.iae_eligibility_diagnosis_required %}
{% if not job_application.jobseeker_valid_eligibility_diagnosis %}
<span class="badge badge-xs rounded-pill bg-accent-02-lighter text-primary">
<i class="ri-error-warning-line" aria-hidden="true"></i>
Éligibilité IAE à valider
Expand Down
7 changes: 0 additions & 7 deletions itou/www/apply/views/list_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ def _add_administrative_criteria(job_applications):
job_application.preloaded_administrative_criteria_extra_nb = extra_nb


def _add_eligibility_diagnosis_required(job_applications):
for job_app in job_applications:
job_app.iae_eligibility_diagnosis_required = job_app.eligibility_diagnosis_by_siae_required()


@login_required
@user_passes_test(lambda u: u.is_job_seeker, login_url=reverse_lazy("search:employers_home"), redirect_field_name=None)
def list_for_job_seeker(request, template_name="apply/list_for_job_seeker.html"):
Expand Down Expand Up @@ -164,7 +159,6 @@ def list_prescriptions(request, template_name="apply/list_prescriptions.html"):
_add_pending_for_weeks(job_applications_page)
_add_user_can_view_personal_information(job_applications_page, request.user.can_view_personal_information)
_add_administrative_criteria(job_applications_page)
_add_eligibility_diagnosis_required(job_applications_page)

context = {
"title": title,
Expand Down Expand Up @@ -293,7 +287,6 @@ def list_for_siae(request, template_name="apply/list_for_siae.html"):
iae_company = company.kind in SIAE_WITH_CONVENTION_KINDS
if iae_company:
_add_administrative_criteria(job_applications_page)
_add_eligibility_diagnosis_required(job_applications_page)

context = {
"title": title,
Expand Down
Loading