Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

While it is problematic, the description here is not quite correct.

persistent entity caching does include hook_node_load(), only hook_node_storage_load(), hook_node_load() is still called once per request. But of course, if the user switches, then it is broken as well.

dawehner’s picture

Status: Active » Needs review
FileSize
6 KB

Started to work on this issue: Added some multiloading for nodes in the book, and ported over some of the menu link improvements.

persistent entity caching does include hook_node_load(), only hook_node_storage_load(), hook_node_load() is still called once per request. But of course, if the user switches, then it is broken as well.

Well, in general I think switching users, at least manually is an edge case.
In general I think its a sign that we really can't just authenticate after routing, i'm still convinced that lazy-authentication ensures that you never deal with the wrong user.

Status: Needs review » Needs work

The last submitted patch, 2: 2380615-2.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
3.37 KB
9.87 KB

Some work.

Status: Needs review » Needs work

The last submitted patch, 4: 2380615-4.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
9.91 KB

Now, some propery work.

Status: Needs review » Needs work

The last submitted patch, 6: 2380615-6.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
2.22 KB

New, much more simpler approach.

dawehner’s picture

FileSize
2.66 KB
4.87 KB

This time with a test as well.

Berdir’s picture

+++ b/core/modules/book/src/BookOutlineStorage.php
@@ -47,11 +47,15 @@ public function hasBooks() {
+    if ($access) {
+      $query->addTag('node_access');
+    }
+
     $query->addMetaData('base_table', 'book');

Would make sense to add the metadata inside the if as well, as that belongs together?

dawehner’s picture

FileSize
514 bytes
4.92 KB

Valid point, thank you!

The last submitted patch, 9: 2380615-9-test.patch, failed testing.

The last submitted patch, 9: 2380615-9.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 11: 2380615-11.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
593 bytes
5.5 KB

Doh, I was sure I fixed that already.

swentel’s picture

+++ b/core/modules/book/src/Tests/BookTest.php
@@ -660,4 +668,35 @@ public function testAdminBookListing() {
+    // Ensure that the loaded book in hook_node_lode() does NOT depend on the

typo: hook_node_lode()

dawehner’s picture

FileSize
677 bytes
5.5 KB

Ha, a lode though seems to be a real existing thing: http://en.wikipedia.org/wiki/Lode

Status: Needs review » Needs work

The last submitted patch, 17: 2380615-17.patch, failed testing.

Status: Needs work » Needs review

swentel queued 17: 2380615-17.patch for re-testing.

larowlan’s picture

- * @return array - * Array of loaded book items. + * @return array Array of loaded book items. + * Array of loaded book items. */
Other Than this, rtbc

swentel’s picture

FileSize
5.42 KB
734 bytes
larowlan’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
81.59 KB

Looks good, tests fine

larowlan’s picture

Screenshot

alexpott’s picture

+++ b/core/modules/book/src/BookManager.php
@@ -695,7 +695,7 @@ public function loadBookLink($nid, $translate = TRUE) {
+    $result = $this->bookOutlineStorage->loadMultiple($nids, $translate);

+++ b/core/modules/book/src/BookOutlineStorage.php
@@ -47,12 +47,16 @@ public function hasBooks() {
+  public function loadMultiple($nids, $access = TRUE) {

This looks super odd - why are we passing boolean about translation into a variable about access?

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Back to needs review for #24 - if this is correct perhaps a comment in the code would be nice.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This looks super odd - why are we passing boolean about translation into a variable about access?

Coming from the good old days of from menu.inc we have this odd thing called translating.
Translating is pretty much access checking though these days (

* Provides book loading, access control and translation.

See the following code:

  public function bookLinkTranslate(&$link) {
    $node = NULL;
    // Access will already be set in the tree functions.
    if (!isset($link['access'])) {
      $node = $this->entityManager->getStorage('node')->load($link['nid']);
      $link['access'] = $node && $node->access('view');
    }
    // For performance, don't localize a link the user can't access.
    if ($link['access']) {
      // @todo - load the nodes en-mass rather than individually.
      if (!$node) {
        $node = $this->entityManager->getStorage('node')
          ->load($link['nid']);
      }
      // The node label will be the value for the current user's language.
      $link['title'] = $node->label();
      $link['options'] = array();
    }
    return $link;
  }

Having a better name would require API changes, let's avoid this here. So back to RTBC

webchick’s picture

Assigned: Unassigned » alexpott

Back to Alex.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  /**
   * Loads multiple book entries.
   *
   * @param int[] $nids
   *   An array of nids to load.
   *
   * @param bool $translate
   *   If TRUE, set access, title, and other elements.
   *
   * @return array[]
   *   The book data of each node keyed by NID.
   */
  public function loadBookLinks($nids, $translate = TRUE);

The documentation for loadBookLinks looks like it could do with improving considering how this issue changes things. Since this is now about respecting access and therefore has security implications.

dawehner’s picture

Status: Needs work » Needs review
FileSize
6.98 KB
1.96 KB

There we go.

znerol’s picture

Applying that patch on top of #2286971: Remove dependency of current_user on request and authentication manager fixes the failing BookTest over there.

larowlan’s picture

Status: Needs review » Needs work
+++ b/core/modules/book/src/BookManagerInterface.php
@@ -57,6 +57,14 @@ public function getActiveTrailIds($bid, $link);
+   *
+   * On top of it, loadBookLinks

This looks orphaned - should it be a @see?

dawehner’s picture

Status: Needs work » Needs review
FileSize
263.78 KB
1.09 KB

This looks orphaned - should it be a @see?

Yeah sure, let's add a @see

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Back we go

dawehner’s picture

FileSize
7.42 KB

Let's do a better rebase

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 2874862 and pushed to 8.0.x. Thanks!

  • alexpott committed 2874862 on 8.0.x
    Issue #2380615 by dawehner, swentel, larowlan: Result of book_node_load...

Status: Fixed » Closed (fixed)

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