Skip to content

Commit

Permalink
Item12952: Cache the checkers
Browse files Browse the repository at this point in the history
No sense trying to load type checkers over and over.
  • Loading branch information
gac410 committed Sep 23, 2014
1 parent c73dfa4 commit afddc81
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions core/lib/Foswiki/Configure/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ confirm this setting (and any other guessed settings) and save
correct values before changing any other settings.
HERE

my %checkers;

# Construct a new Checker, attaching the given $item from the model.
# This is not normally used by other classes, but is provided in case
# a subclass needs to override it for any reason.
Expand Down Expand Up @@ -100,17 +102,37 @@ sub loadChecker {
and substr( $id, -2 ) = '';
}

my $checkClass = 'Foswiki::Configure::Checkers::' . $id;
eval "require $checkClass";
unless ($@) {
return $checkClass->new($item);
}
foreach my $chkmod ( $id, $item->{typename} ) {
if ( defined $checkers{$chkmod} ) {
if ( $checkers{$chkmod} ) {

# See if a generic type checker exists for this type
$checkClass = 'Foswiki::Configure::Checkers::' . $item->{typename};
eval "require $checkClass";
unless ($@) {
return $checkClass->new($item);
#print STDERR "Returning cached $chkmod\n";
return $checkers{$chkmod}->new($item);
}
}
else {
my $checkClass = 'Foswiki::Configure::Checkers::' . $chkmod;
if (
Foswiki::Configure::FileUtil::findFileOnPath(
$checkClass . '.pm'
)
)
{
eval "require $checkClass";
unless ($@) {
$checkers{$chkmod} = $checkClass;

#print STDERR "Returning NEW cached $chkmod\n";
return $checkClass->new($item);
}
else {
die "Checker $checkClass failed to load: $@\n";
}
}

#print STDERR "Caching empty $chkmod\n";
$checkers{$chkmod} = '';
}
}
return undef;
}
Expand Down

0 comments on commit afddc81

Please sign in to comment.