From ebe0107b20bf3bf7c7b78546fd3020368c4be12b Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Wed, 30 Sep 2020 15:45:12 -0400 Subject: [PATCH] Improve explanation for installedSet, put its values as true, not null --- src/Extension/ExtensionManager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Extension/ExtensionManager.php b/src/Extension/ExtensionManager.php index be9099d344..3a71415d51 100644 --- a/src/Extension/ExtensionManager.php +++ b/src/Extension/ExtensionManager.php @@ -84,9 +84,11 @@ public function getExtensions() $installed = $installed['packages'] ?? $installed; // We calculate and store a set of installed extension IDs (associative array with null keys) - // to avoid an O(n * m) complexity when finding extension dependencies. + // to avoid O(n * m) complexity when finding extension dependencies. // By only including flarum extensions, we know that anything present in this associative copy // is a flarum extension, removing the need to check for it's type. + // We store the installed flarum extensions as keys, not values, of this array + // so that we have constant lookup time. $installedSet = []; foreach ($installed as $package) { @@ -94,7 +96,7 @@ public function getExtensions() continue; } - $installedSet[Arr::get($package, 'name')] = null; + $installedSet[Arr::get($package, 'name')] = true; $path = isset($package['install-path']) ? $this->paths->vendor.'/composer/'.$package['install-path'] @@ -110,6 +112,8 @@ public function getExtensions() $extensions->put($extension->getId(), $extension); } + $installedSet = $extensions->pluck('name')->toArray(); + foreach ($extensions as $extension) { $extension->calculateDependencies($installedSet); }