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

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

Merged
merged 1 commit into from
May 9, 2024

Conversation

francoisfreitag
Copy link
Contributor

🤔 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.

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
Contributor 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
11 checks passed
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants