-
Notifications
You must be signed in to change notification settings - Fork 7
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
NEMA-2900: Change OR Query into OR Condition Group #125
base: master
Are you sure you want to change the base?
NEMA-2900: Change OR Query into OR Condition Group #125
Conversation
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.
Please provide test coverage for this part. Create a test submodule that simulates what the groups module does.
oe_media.module
Outdated
@@ -62,10 +62,13 @@ function oe_media_media_access(EntityInterface $entity, string $operation, Accou | |||
} | |||
|
|||
// 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(); |
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.
Variable name should be snake_case.
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. |
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).