From 8796b7de71e5fd5e904617de1d61a772767dff33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 27 Sep 2023 15:09:06 +0200 Subject: [PATCH] Store the license data in serialized form This avoids expensive remapping on every request. --- .../package/license/LicenseApi.class.php | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php index bd669d3cd1..82c9d77b64 100644 --- a/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php +++ b/wcfsetup/install/files/lib/system/package/license/LicenseApi.class.php @@ -22,14 +22,12 @@ use wcf\system\package\license\exception\ParsingFailed; final class LicenseApi { private readonly LicenseData $data; - private readonly string $json; private const LICENSE_FILE = \WCF_DIR . 'license.php'; - private function __construct(string $json) + private function __construct(LicenseData $data) { - $this->json = $json; - $this->data = $this->parseLicenseData($this->json); + $this->data = $data; } public function getData(): LicenseData @@ -45,17 +43,15 @@ final class LicenseApi <<<'EOT' json, + \var_export(\serialize($this->data), true), ) ); } - private function parseLicenseData(string $json): LicenseData + private static function parseLicenseData(string $json): LicenseData { try { return (new MapperBuilder()) @@ -95,7 +91,7 @@ final class LicenseApi $response = HttpFactory::makeClientWithTimeout(5)->send($request); - return new LicenseApi($response->getBody()); + return new LicenseApi(self::parseLicenseData($response->getBody())); } public static function readFromFile(): ?LicenseApi @@ -104,13 +100,7 @@ final class LicenseApi return null; } - $content = require(self::LICENSE_FILE); - - try { - return new LicenseApi($content); - } catch (ParsingFailed) { - return null; - } + return new LicenseApi(require(self::LICENSE_FILE)); } public static function removeLicenseFile(): void -- 2.20.1