diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b43c8fb5..b80cd01da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.5.6 +## mm/dd/2018 + +1. [](#improved) + * Improved user serialization to use less memory in the session + # v1.5.5 ## 11/12/2018 diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index 4da55d9eb..0fc9bb3b4 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -82,4 +82,28 @@ trait CompiledFile return parent::content($var); } + + /** + * Serialize file. + */ + public function __sleep() + { + return [ + 'filename', + 'extension', + 'raw', + 'content', + 'settings' + ]; + } + + /** + * Unserialize file. + */ + public function __wakeup() + { + if (!isset(static::$instances[$this->filename])) { + static::$instances[$this->filename] = $this; + } + } } diff --git a/system/src/Grav/Common/User/User.php b/system/src/Grav/Common/User/User.php index 438ca97a7..9cce364fd 100644 --- a/system/src/Grav/Common/User/User.php +++ b/system/src/Grav/Common/User/User.php @@ -286,4 +286,29 @@ class User extends Data return 'https://www.gravatar.com/avatar/' . md5($this->email); } + + /** + * Serialize user. + */ + public function __sleep() + { + return [ + 'items', + 'storage' + ]; + } + + /** + * Unserialize user. + */ + public function __wakeup() + { + $this->gettersVariable = 'items'; + $this->nestedSeparator = '.'; + + if (null === $this->blueprints) { + $blueprints = new Blueprints; + $this->blueprints = $blueprints->get('user/account'); + } + } }