Skip to content

Explore: Optimize removing from a to-many relationship #1030

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

Closed
bart-degreed opened this issue Jul 19, 2021 · 0 comments · Fixed by #1039
Closed

Explore: Optimize removing from a to-many relationship #1030

bart-degreed opened this issue Jul 19, 2021 · 0 comments · Fixed by #1039

Comments

@bart-degreed
Copy link
Contributor

For adding resources to a to-many relationship (example: POST /shop/1/relationships/articles), we don't fetch all existing articles first. This makes adding a few articles to an existing large set efficient.

But for removing resources from a to-many relationship (example: DELETE /shop/1/relationships/articles), we rely on EF Core to fetch the existing set of articles first. If that set is large, the operation becomes very inefficient.

This issue concerns exploring if we can do better. At the minimum, we'll need to fetch the set of resources-to-be-deleted (which is usually empty), so that we won't fail when a user is detaching something that wasn't attached (JSON:API requires that). We'll need to look for ways to trick the EF Core change tracker into believing the whole set was fetched.

If we don't find a way to optimize this, we should put some controls in place that prevent clients from taking down the service on such incoming requests. For example, we could choose to add a configurable threshold for the existing number of items in the set. If this setting is activated, we'll do a COUNT(*) on the set before trying the operation. If the count exceeds the threshold, we'll abort with an error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

1 participant