Commit 54a49d50 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2313053 by Berdir: Fixed Field storage and instance call toArray() in...

Issue #2313053 by Berdir: Fixed Field storage and instance call toArray() in __wakeup() is very slow, remove it?.
parent e6657946
Loading
Loading
Loading
Loading
+6 −15
Changes for core/modules/field/src/Entity/FieldInstanceConfig.php: 6 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -617,7 +617,7 @@ public function targetBundle() {
    return $this->bundle;
  }

  /*
  /**
   * Implements the magic __sleep() method.
   *
   * Using the Serialize interface and serialize() / unserialize() methods
@@ -625,20 +625,11 @@ public function targetBundle() {
   * @todo Investigate in https://drupal.org/node/2074253.
   */
  public function __sleep() {
    // Only serialize properties from self::toArray().
    $properties = array_keys(array_intersect_key($this->toArray(), get_object_vars($this)));
    // Serialize $entityTypeId property so that toArray() works when waking up.
    $properties[] = 'entityTypeId';
    return $properties;
  }

  /**
   * Implements the magic __wakeup() method.
   */
  public function __wakeup() {
    // Run the values from self::toArray() through __construct().
    $values = array_intersect_key($this->toArray(), get_object_vars($this));
    $this->__construct($values);
    // Only serialize necessary properties, excluding those that can be
    // recalculated.
    $properties = get_object_vars($this);
    unset($properties['fieldStorage'], $properties['itemDefinition'], $properties['bundle_rename_allowed']);
    return array_keys($properties);
  }

  /**
+5 −14
Changes for core/modules/field/src/Entity/FieldStorageConfig.php: 5 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -642,20 +642,11 @@ public function hasData() {
   * @todo Investigate in https://drupal.org/node/2074253.
   */
  public function __sleep() {
    // Only serialize properties from self::toArray().
    $properties = array_keys(array_intersect_key($this->toArray(), get_object_vars($this)));
    // Serialize $entityTypeId property so that toArray() works when waking up.
    $properties[] = 'entityTypeId';
    return $properties;
  }

  /**
   * Implements the magic __wakeup() method.
   */
  public function __wakeup() {
    // Run the values from self::toArray() through __construct().
    $values = array_intersect_key($this->toArray(), get_object_vars($this));
    $this->__construct($values);
    // Only serialize necessary properties, excluding those that can be
    // recalculated.
    $properties = get_object_vars($this);
    unset($properties['schema'], $properties['propertyDefinitions']);
    return array_keys($properties);
  }

  /**