Problem/Motivation
We're talking at https://www.drupal.org/project/drupal/issues/106721#comment-14115502 and on the file
core/modules/node/src/NodeGrantDatabaseStorage.php
there is a method buildGrantsQueryCondition that we can use early return to be easier to ready and avoid Hadouken effect
Proposed resolution
Change from:
protected function buildGrantsQueryCondition(array $node_access_grants) {
$grants = $this->database->condition('OR');
foreach ($node_access_grants as $realm => $gids) {
if (!empty($gids)) {
$and = $this->database->condition('AND');
$grants->condition($and
->condition('gid', $gids, 'IN')
->condition('realm', $realm)
);
}
}
return $grants;
}
To:
protected function buildGrantsQueryCondition(array $node_access_grants) {
$grants = $this->database->condition('OR');
foreach ($node_access_grants as $realm => $gids) {
if (empty($gids)) {
continue;
}
$and = $this->database->condition('AND');
$grants->condition($and
->condition('gid', $gids, 'IN')
->condition('realm', $realm)
);
}
return $grants;
}
Comments
Comment #2
renatog commentedThis is the patch with the fix
Comment #3
renatog commentedThis is the correct patch
Comment #4
renatog commentedPlease discard the other patches. This is the correct patch
Comment #8
diegorsNice implementation @RenatoG!
Moving to RTBC!
Comment #9
diegorsTests are failing in Drupal 9.2.x, I will work on it.
Comment #10
diegorsAs this patch apply successfully in Drupal 9.2.x and 9.5.x, and implements an early return, for me makes sense to keep in RTBC, if someone disagrees please move back.
Comment #11
bhanu951 commentedChanges should be applied to latest Head and Back-ported. Hence updating Version.
Comment #12
alexpottThere's no performance benefit from this change and the readability benefits are debatable. If the code inside the
if (!empty($gids)) {was large then maybe this would be more readable. Also the issue is not titled correctly we're not doing an early return - we're using continue in a foreach loop. I think committing this patch would set us up for lots of similar issues which would take time to implement, review and commit for little to no benefit.Discussed with @catch we agreed to close this.