Hi,
i want to start a discussion about the book module and some SQL query that can be really huge.
Step to reproduce :
Use Drupal 8.7 with book module enable.
Add 2000 node content, no need to be allowed book content type.
Create a view on the homepage to display all the 2000.
You will see a SQL query : SELECT * FROM book b where b.nid IN (
)
This request is slow and not really usefull, because we are just looking of the content that can be books.
I would imagine that we can improve this query in 2 differents ways:
- limit to the node that are from the allowed book type (/admin/structure/book/settings)
- limit to the existing book node (/admin/structure/book)
I don't know which is the best option. But in my case i patch the module with the first option.
This is suffisant in my use case.
Past issue (for drupal 7) with the same problem and same solution: https://www.drupal.org/project/drupal/issues/2070807
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | interdiff-3096844-2_7.txt | 1.04 KB | poker10 |
| #7 | 3096844_7.patch | 1.44 KB | poker10 |
| #2 | 3096844-Book-performance-problem-node-load-1.patch | 1.46 KB | tomefa |
Issue fork book-3096844
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tomefa commentedHere the patch
Comment #7
poker10 commentedThe patch does not applied anymore. Uploading a reroll with some cosmetic changes (like that we do not need to create a second array of nodes if all we need are NIDs).
Comment #9
poker10 commentedHmm, it seems like that the failures are not a problem of this patch, but are related to the
allowed_typessettings.In those failing migration tests this settings returns NULL. Then it will throw PHP 8 typerror:
So I think we need to either fix those migration tests, or change the
book_type_is_allowed()function to count on the possibility, that NULL can be returned.Either way it seems to me that a new issue should be created for this, as this is out of scope of this. Any thoughts?
Comment #10
mcdruid commentedAdded a related issue where D7 was able to fix this relatively simply as
hook_node_load()is passed a list of$types.Comment #11
pwolanin commentedIt looks like the function is just sloppy, and yes, we should make sure getting the config gives you and array (and/or cast it to array).
Also, if you are possibly loading many nodes here, it would be faster (IDK if enough to matter?) to inline the check to reduce the number of confg get() calls you have to make?
Comment #13
poker10 commentedThis turned out to be more complicated, since the
allowed_typesvariable cannot be relied upon. Users with "Administer book outlines" permission can add all types to book outlines. Therefore if we restrictbook_node_loadfor such nodes, it will make these books unusable.See:
#2862291: [Duplicate] Book outline not limited to allowed content types
#502430: Allow the book outline functionality on non-book-enabled node types to be hidden from users with the "Administer book outlines" permission
If this behavior is a feature, as explained in those linked issues, this needs to be at least postponed until mentioned issues are resolved. Second option is to close this as Won't fix, but the performance issues are there and better to think how we can solve them.
Comment #14
poker10 commentedComment #15
quietone commentedThis extension is being deprecated, see #3376070: [Meta] Tasks to deprecate Book module. It will be removed from core and moved to a contrib project, #3376101: [11.x] [Meta] Tasks to remove Book.
This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
This issue may be re-opened if it can be considered critical, If unsure, re-open the issue and ask in a comment.
Comment #17
smustgrave commentedComment #18
smustgrave commentedJust merged #502430: Allow the book outline functionality on non-book-enabled node types to be hidden from users with the "Administer book outlines" permission wonder if this is now still needed?
Comment #21
smustgrave commented