workflow_buttons should only be loaded/load edit form when relevant

Created on 21 December 2022, over 1 year ago
Updated 2 August 2023, 11 months ago

I found out that my site has some major performance issues, and after digging, it appears that it's in relation to this module.

The module uses hook_entity_view and hook_preprocess_node, regardless of view_mode.
That is especially an issue with hook_entity_view, as it builds the whole edit form, on all nodes.

That means that if you have a view with 100 teasers, it'll load 100 edit forms.
That's obviously not good.

My simple fix is just to add a check if the viewmode is full or not

But in reality, there's two things that i would say needs to be added:

- A config setting, so we can choose if we want the buttons to be displayed on the node view
- A check, to make sure that the user actually has permissions to use workflows - so we can avoid heavy operations for anonymous users.

Patch attached for the simple quickfix.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡°Denmark ras-ben Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States beunerd Providence, Rhode Island

    @ras-ben, @mlncn

    Sorry just getting to this now. Please help me understand what the problem is here, because I don't see it! And I think the fix that was merged in disables some of the module's intended flexibility and utility.

    The first of the hooks mentioned in the issue description (hook_entity_view()) is there to show the workflow buttons if they're included in the list of enable components for the node type / view mode loaded. We shouldn't be hard-coding a restriction here for some particular view mode with an arbitrary machine name. That restriction is handled by the view mode's configuration itself. Perhaps we need to add the workflow buttons to the list of disabled components for all workflows by default and let users "opt in" to including them on the various node views, but that preserves the flexibility here. This is not so different from enabling comments on a node type.

    The second of the hooks mentioned (hook_preprocess_node()) passes the latest revision workflow state to the node template. That's it. True, it does do an extra load of the $node object to get a list of its revision ids, but there's no rendering or anything heavy going on here.

    What am I missing here?

  • πŸ‡ΊπŸ‡ΈUnited States beunerd Providence, Rhode Island

    @ras-ben, @mlncn

    I think the comments above address the first proposed feature, and regarding the second ("A check, to make sure that the user actually has permissions to use workflows - so we can avoid heavy operations for anonymous users.") that's already handled by Drupal's standard access methods. If an anonymous user can use a transition in the content moderation permissions collection, then they can see the buttons; if they do not have those permissions then the buttons do not appear for them. Again, I might be misunderstanding the problem.

    • beunerd β†’ committed b45f5d09 on 8.x-1.x
      Revert "Issue #3328538 by ras-ben, mlncn: workflow_buttons should only...
  • Status changed to Closed: works as designed 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States beunerd Providence, Rhode Island

    @ras-ben, @mlncn

    I'm going to revert this change per the explanation above.

  • πŸ‡©πŸ‡°Denmark ras-ben Copenhagen

    Sorry for the slow reply, Beunerd.

    You have a good point, in regards to view mode. However, I think it should most definetely be a "opt in" view mode, as otherwise, there's a massive performance issue.

    In regards to the anonymous-user-avoid-bla-bla - yes - you're right, and my comment was irrelevant.

  • Status changed to Fixed 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States beunerd Providence, Rhode Island

    @ras-ben

    Thanks, that's a good idea. I've added a commit to the 8.x.-1.x branch. Marking this as fixed.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024