Skip to content
Permalink
Browse files

Add distribution cache to CURFS

Cache the generated Distribution to avoid doing directory recursion, as discovered by @niner. It also clears the cache when it finds an existing file that was not discovered during the initial generation of the Distribution. It is debatable if clearing the cache is ideal, but it is the current behavior according to a roast test that fails if caching is added without the clearer.
  • Loading branch information...
ugexe committed Dec 23, 2018
1 parent c07cfe7 commit 83f0fd6c993c6bbf6ce9deeb3279953e70acf244
Showing with 14 additions and 4 deletions.
  1. +14 −4 src/core/CompUnit/Repository/FileSystem.pm6
@@ -5,6 +5,7 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
has $!id;
has $!precomp-stores;
has $!precomp-store;
has $!distribution;

my @extensions = <pm6 pm>;

@@ -151,9 +152,17 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
multi method candidates(CompUnit::DependencySpecification $spec) {
return Empty unless $spec.from eq 'Perl6';

my $distribution := self!distribution;
return Empty unless ($distribution.meta<provides> && $distribution.meta<provides>{$spec.short-name})
or ($distribution.meta<files> && $distribution.meta<files>{$spec.short-name});
my $distribution = self!distribution;

unless ($distribution.meta<provides> && $distribution.meta<provides>{$spec.short-name})
or ($distribution.meta<files> && $distribution.meta<files>{$spec.short-name})
{
# Break the !distribution cache if we failed to find a match using the cached distribution
# but still found an existing file that matches the $spec.short-name
return Empty unless @extensions.map({ $!prefix.add($spec.short-name.subst(:g, "::", $*SPEC.dir-sep) ~ ".$_") }).first(*.f);
$!distribution = Nil;
$distribution = self!distribution;
}

my $version-matcher = ($spec.version-matcher ~~ Bool)
?? $spec.version-matcher
@@ -210,6 +219,7 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
}

method !distribution {
return $!distribution if $!distribution.defined;
# Path contains a META6.json file, so only use paths/modules explicitly declared therein ( -I ./ )
my $dist = $!prefix.add('META6.json').f
?? Distribution::Path.new($!prefix)
@@ -235,7 +245,7 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
));
};

return CompUnit::Repository::Distribution.new($dist);
return $!distribution = CompUnit::Repository::Distribution.new($dist);
}

method resource($dist-id, $key) {

0 comments on commit 83f0fd6

Please sign in to comment.
You can’t perform that action at this time.