-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(repository): hasManyThrough can delete correct target n through based on filter #5858
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
Conversation
packages/repository/src/relations/has-many/has-many-through.repository.ts
Outdated
Show resolved
Hide resolved
packages/repository-tests/src/crud/relations/acceptance/has-many-through.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good 👏 I have few comments to consider, see below.
It would be great to get a review from somebody more familiar with this area of our codebase.
packages/repository-tests/src/crud/relations/acceptance/has-many-through.relation.acceptance.ts
Outdated
Show resolved
Hide resolved
packages/repository/src/__tests__/integration/repositories/relation.factory.integration.ts
Show resolved
Hide resolved
|
|
||
| if (where) { | ||
| // only delete related through models | ||
| const targets = await targetRepository.find({where: where}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we already have a list of troughInstances, is there a way how to limit this query to find only target models that are matching the user-provided where and are related to the source model(s)?
I am concerned about performance implication of the current solution, because it may fetch too many records. Consider the case Doctor-Appointment-Patient case, where we want to delete all appointment+patient records of the given doctor where the patient has {died: true}. Let's say our database is large (e.g. ~100k doctors). For each doctor, there will be only few patients that have passed away (e.g. 1-10). Ideally, we should fetch only those 1-10 patients, not ~100k-1000k passed-away patients of all doctors.
I am fine to leave this performance optimization out of scope of the initial implementation, as long as we have some documentation for this known performance issue (a code comment is good enough).
A nitpick on coding style:
| const targets = await targetRepository.find({where: where}); | |
| const targets = await targetRepository.find({where}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍. I couldn't find a way to fix it without accessing to the database, but we can improve it by limiting how many records it fetches.
I think it needs more helpers to build such a where filter. I left a TODO comment.
jannyHou
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM and agreed with Miroslav's comment about the performance.
bajtos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Please remember to clean up the commit history before landing :)
fixes #5852
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm testpasses on your machinepackages/cliwere updatedexamples/*were updated👉 Check out how to submit a PR 👈