Skip to content

Admin : Éviter les doublons lorsqu’on liste les PASS IAE d’une entreprise#4047

Merged
francoisfreitag merged 1 commit intomasterfrom
ff/admin-count
May 9, 2024
Merged

Admin : Éviter les doublons lorsqu’on liste les PASS IAE d’une entreprise#4047
francoisfreitag merged 1 commit intomasterfrom
ff/admin-count

Conversation

@francoisfreitag
Copy link
Member

🤔 Pourquoi ?

Si un candidat avait émit plusieurs candidatures vers une entreprise, son PASS était listé une fois par candidature.

🍰 Comment ?

Exists

🏝️ Comment tester

Comparer /admin/approvals/approval/?assigned_company=11919&o=2.-6 entre la prod et cette branche.

@francoisfreitag francoisfreitag added the modifié Modifié dans le changelog. label May 7, 2024
@francoisfreitag francoisfreitag self-assigned this May 7, 2024
@francoisfreitag francoisfreitag requested a review from rsebille May 7, 2024 13:19
Copy link
Contributor

@rsebille rsebille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


return (
self.filter(user__job_applications__to_company=company_id)
self.filter(Exists(JobApplication.objects.filter(approval=OuterRef("pk"), to_company=company_id)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De ce que je comprend ça va faire la sous-requête pour chaque ligne donc dans le cas présent ça serait pas plus efficace d'utiliser d'un IN ?

Suggested change
self.filter(Exists(JobApplication.objects.filter(approval=OuterRef("pk"), to_company=company_id)))
self.filter(pk__in=Subquery(JobApplication.objects.filter(to_company=company_id).values("approval")))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Et bien... c’est équivalent 😂
Le EXPLAIN de DjDT donne le même plan d’exécution, peu importe la forme. J’ai inclus la requête dans les deux cas, où on voit bien soit le IN soit le EXISTS(). Je suppose que PostgreSQL est malin et prend l’opération la plus efficace pour réaliser la requête, peu importe la forme demandée.

exists.sql.gz
in.sql.gz

J’ai préféré ta version qui me semble effectivement plus simple 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep mais à mon avis ça dépend aussi de ce que tu lui demandes à coté, là c'est probablement lié à l'annotation assigned_company qui tape sur la même table et donc il optimise le travail, sur un truc plus simple c'est pas dit.

@francoisfreitag francoisfreitag added this pull request to the merge queue May 9, 2024
Merged via the queue into master with commit 4985818 May 9, 2024
@francoisfreitag francoisfreitag deleted the ff/admin-count branch May 9, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

modifié Modifié dans le changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants