NEMA-2900: Change OR Query into OR Condition Group#125
Open
cosmin-flo-tr wants to merge 2 commits intoopeneuropa:masterfrom
Open
NEMA-2900: Change OR Query into OR Condition Group#125cosmin-flo-tr wants to merge 2 commits intoopeneuropa:masterfrom
cosmin-flo-tr wants to merge 2 commits intoopeneuropa:masterfrom
Conversation
brummbar
requested changes
Sep 21, 2020
Contributor
brummbar
left a comment
There was a problem hiding this comment.
Please provide test coverage for this part. Create a test submodule that simulates what the groups module does.
oe_media.module
Outdated
| // Get all the nodes which use this media entity. | ||
| $query = $entity_type_manager->getStorage('node')->getQuery('OR'); | ||
| $query = $entity_type_manager->getStorage('node')->getQuery(); | ||
| $orGroup = $query->orConditionGroup(); |
Contributor
There was a problem hiding this comment.
Variable name should be snake_case.
Contributor
|
Hello @brummbar The final query before MR: The final query after MR: Notice the diff in both queries (I put it between ** **) I confirm, the MR proposed by @cosmin-flo-tr is fixing the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NEMA-2900
Description
The issue: The SQL query may get extended by other modules (contrib or custom) before getting executed. If the OR conjunction is applied globally, everything that's being extended will be OR-ed. This will surely make the query incorrect.
Our case: group contrib module is extending the queries with its own checks for anonymous users. Instead of constraining the query, it does the opposite because of the OR conjunction.
The result was that even if we have 1 field and 1 entity ID, the query would select all the nodes in the system. Given there are 100k+ nodes, the query would timeout. Again, this happens for guests and, most likely, non-admins.
Change log
Moved the global OR conjunction into an OR-ed condition group. This ensures that the OR will get applied to the checked fields only. Any other checks will be added with AND (the default).