Skip to content
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

Fix for #3039636 #129

Merged
merged 1 commit into from
Apr 13, 2019
Merged

Fix for #3039636 #129

merged 1 commit into from
Apr 13, 2019

Conversation

larowlan
Copy link
Collaborator

@larowlan larowlan commented Mar 13, 2019

https://www.drupal.org/project/workbench_access/issues/3039636

Profiling result of applying the patch/fix

Screen Shot 2019-03-13 at 2 24 59 pm

@@ -172,12 +172,6 @@ public function load($id) {
* {@inheritdoc}
*/
public function checkEntityAccess(AccessSchemeInterface $scheme, EntityInterface $entity, $op, AccountInterface $account) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain this code isn't called anywhere else?

@@ -63,7 +63,11 @@ function workbench_access_form_alter(&$form, FormStateInterface $form_state) {
function workbench_access_entity_access(EntityInterface $entity, $op, AccountInterface $account) {
// Return net result of all enabled access schemes. If one scheme allows
// access, then it is granted.
$manager = \Drupal::service('plugin.manager.workbench_access.scheme');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the point to the service here is to enable issues like #122.

IS loading the service really that much of a performance hit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstorm is reporting $manager as unused, so I removed it. tests pass so I think its safe to remove the variable

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but is it called by any other code? We're changing the behavior of the service....

I'm on the road and can look more deeply tomorrow.

@larowlan
Copy link
Collaborator Author

larowlan commented Mar 14, 2019 via email

@larowlan
Copy link
Collaborator Author

larowlan commented Mar 14, 2019 via email

@larowlan
Copy link
Collaborator Author

@agentrickard any updates on this, big performance boost

@agentrickard
Copy link
Owner

No updates. I'm totally swamped.

My issue here is that I think the 'view' $op check belongs in the method because that class is a service, and the method should be opinionated.

I think we can have the logic in both places for performance reasons, but I wouldn't move the $op check.

if ($op === 'view' || $op === 'view label' || $account->hasPermission('bypass workbench access')) {
// Return early.
return AccessResult::neutral();
}
return array_reduce(\Drupal::entityTypeManager()->getStorage('access_scheme')->loadMultiple(), function (AccessResult $carry, AccessSchemeInterface $scheme) use ($entity, $op, $account) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have totally misread this patch because the anonymous function here calls the $manager directly. I kept misreading that we were loading checkEntityAccess() from a service and not a base class.

This is one reason why I despise anonymous functions. Every time we use array_reduce in this code, I can't follow the logic easily.

@agentrickard agentrickard merged commit ed55ad0 into 8.x-1.x Apr 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants