-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DoctrineBridge] [Validator] UniqueEntityValidator should limit the retrieved entities to 2
to avoid potential memory issues with broad
queries
#43254
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
Comments
Sounds reasonable to me. As this looks like a performance improvement to me a PR should be opened against the @AndreasA Up to give it a try? |
@xabbuh I can't guarantee that I will find the time but I will try to create a PR next week. It should be rather straight forward. |
No need to test the performance change for this change IMHO. |
OK. Great. I hope I will find time this week but can't guarantee it. Sadly, I didn't find time the last two weeks. |
One remaining question though. How dynamic does it need to be? because supporting it for the I could only add the limit parameter, if the default method |
Let's optimize for the simple and default |
I agree with @fabpot. |
Created a PR now (for docs and symfony). Hopefully I did everything correctly, first symfony PR. However, one integration test is failing but it shouldn't be related to my PR at all (MemcacheAdapter)? |
…heck uniqueness. (AndreasA) This PR was merged into the 5.4 branch. Discussion ---------- UniqueEntityValidator: Retrieve at max two entities to check uniqueness. | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #43254 | License | MIT | Doc PR | symfony/symfony-docs#15965 It is enough to retrieve two entities to check for uniqueness. - No entity returned, it is definitely unique. - Two or more entities returned and it cannot be unique. - One entity returned, it depends on the entity if it is unique or not. By providing a limit it avoids potential performance and memory issues in case the entity uniqueness check is not done on a unique field. Commits ------- f55efc3 UniqueEntityValidator: Retrieve at max two entities for unique entity check.
Symfony version(s) affected: 4.4.* and 5.3.*
Description
It isn't that huge an issue because the validator isn't supposed to be use in this way but in theory it would be possible to check uniqueness against a property that isn't strictly unique, e.g. due to old imported data.
This means that the validator could retrieve all those entities. However, in order to determine uniqueness it is enough to retrieve at max
2
as there are only these scenarios possible:> 1
: Definitely not unique< 1
(= 0
): Definitely unique= 1
: Check if fetched entity is equivalent to current.So there is no reason to retrieve more than
2
and as it is a simple change, I think it should be added.The text was updated successfully, but these errors were encountered: