From f0e006475de0fcf40a601e0279622e50917f5b97 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 25 Jul 2024 11:26:24 +0200 Subject: [PATCH] Add static variable to cache the asset map in memory This change makes it go from a constant ~2ms per call to essentially zero (0.000ms avg on 100 000 iterations) --- .../Markdown/Processing/DynamicMarkdownLinkProcessor.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Markdown/Processing/DynamicMarkdownLinkProcessor.php b/packages/framework/src/Markdown/Processing/DynamicMarkdownLinkProcessor.php index 247a41d3c14..db0e4fc411a 100644 --- a/packages/framework/src/Markdown/Processing/DynamicMarkdownLinkProcessor.php +++ b/packages/framework/src/Markdown/Processing/DynamicMarkdownLinkProcessor.php @@ -50,13 +50,15 @@ protected static function routeMap(): array } /** - * @todo Consider adding caching, since this is not a singleton like the routes. - * * @return array */ protected static function assetMap(): array { - $assetMap = []; + static $assetMap = null; + + if ($assetMap !== null) { + return $assetMap; + } foreach (MediaFile::all() as $mediaFile) { $assetMap[$mediaFile->getPath()] = $mediaFile;