Skip to content

Commit

Permalink
Improve explanation for installedSet, put its values as true, not null
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Sep 30, 2020
1 parent 6b64ebe commit ff3f9e9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Extension/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ 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) {
if (Arr::get($package, 'type') != 'flarum-extension' || empty(Arr::get($package, 'name'))) {
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']
Expand All @@ -110,6 +112,8 @@ public function getExtensions()
$extensions->put($extension->getId(), $extension);
}

$installedSet = $extensions->pluck('name')->toArray();

foreach ($extensions as $extension) {
$extension->calculateDependencies($installedSet);
}
Expand Down

0 comments on commit ff3f9e9

Please sign in to comment.