Skip to content

Commit

Permalink
Cache the output of the retrieved data
Browse files Browse the repository at this point in the history
This makes sure we can call these retrieves in loops without huge
performance changes.
  • Loading branch information
WouterSioen committed Mar 19, 2020
1 parent 734eb8b commit fbaf263
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Composer/DependencyTreeRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

class DependencyTreeRetriever
{
private static $output;

public function getDependencyTree(): string
{
if (!is_null(self::$output)) {
return self::$output;
}

$process = new Process(['composer', 'show', '-t', '-f', 'json']);
$process->run();

if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

return $process->getOutput();
self::$output = $process->getOutput();

return self::$output;
}
}
10 changes: 9 additions & 1 deletion src/Composer/UsedLicensesRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@

class UsedLicensesRetriever
{
private static $output;

public function getComposerLicenses(): string
{
if (!is_null(self::$output)) {
return self::$output;
}

$process = new Process(['composer', 'license', '-f', 'json']);
$process->run();

if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}

return $process->getOutput();
self::$output = $process->getOutput();

return self::$output;
}
}

0 comments on commit fbaf263

Please sign in to comment.