Skip to content

Commit

Permalink
Filtered output in cache to save space.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsteele committed May 31, 2016
1 parent 9293b61 commit b4ebcdf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
5 changes: 1 addition & 4 deletions doc/doc.pl
Expand Up @@ -171,10 +171,7 @@ =head1 SYNOPSIS
}

# Load the manifest
my $oManifest;
my $strManifestCache = "${strBasePath}/resource/manifest.cache";

$oManifest =
my $oManifest =
new BackRestDoc::Common::DocManifest(\@stryKeyword, \@stryRequire, $oVariableOverride, $strDocPath, $bDeploy, $bCacheOnly);

if (!$bNoCache)
Expand Down
25 changes: 13 additions & 12 deletions doc/lib/BackRestDoc/Common/DocExecute.pm
Expand Up @@ -117,20 +117,21 @@ sub executeKey
$$hCacheKey{'err-expect'} = $oCommand->paramGet('err-expect');
}

if ($oCommand->paramTest('output', 'y') || $oCommand->paramTest('show', 'y') || $oCommand->paramTest('variable-key', 'y'))
if ($oCommand->paramTest('output', 'y') || $oCommand->paramTest('show', 'y') || $oCommand->paramTest('variable-key'))
{
$$hCacheKey{'output'} = JSON::PP::true;
}

if (defined($oCommand->fieldGet('exe-highlight', false)))
{
$$hCacheKey{'output'} = JSON::PP::true;
$$hCacheKey{'filter'} = $oCommand->paramTest('filter', 'n') ? JSON::PP::false : JSON::PP::true;
$$hCacheKey{highlight}{'filter'} = $oCommand->paramTest('filter', 'n') ? JSON::PP::false : JSON::PP::true;
$$hCacheKey{highlight}{'filter-context'} = $oCommand->paramGet('filter-context', false, 2);

my @stryHighlight;
$stryHighlight[0] = $oCommand->fieldGet('exe-highlight');
$stryHighlight[0] = $self->{oManifest}->variableReplace($oCommand->fieldGet('exe-highlight'));

$$hCacheKey{'highlight'} = \@stryHighlight;
$$hCacheKey{highlight}{list} = \@stryHighlight;
}

# Return from function and log return values if any
Expand Down Expand Up @@ -174,7 +175,6 @@ sub execute

# Command variables
my $hCacheKey = $self->executeKey($strHostName, $oCommand);
my $strVariableKey = $oCommand->paramGet('variable-key', false);

# Add user to run the command as
$strCommand =
Expand Down Expand Up @@ -257,16 +257,16 @@ sub execute
# $strOutput .= join("\n", @{$$hCacheValue{stderr}});
# }

if ($$hCacheKey{output} && $$hCacheKey{filter} && defined($strOutput))
if ($$hCacheKey{output} && defined($$hCacheKey{highlight}) && $$hCacheKey{highlight}{filter} && defined($strOutput))
{
my $strHighLight = @{$$hCacheKey{highlight}}[0];
my $strHighLight = @{$$hCacheKey{highlight}{list}}[0];

if (!defined($strHighLight))
{
confess &log(ERROR, 'filter requires highlight definition: ' . $strCommand);
}

my $iFilterContext = $oCommand->paramGet('filter-context', false, 2);
my $iFilterContext = $$hCacheKey{highlight}{'filter-context'};

my @stryOutput = split("\n", $strOutput);
undef($strOutput);
Expand Down Expand Up @@ -352,9 +352,9 @@ sub execute
}

# Output is assigned to a var
if (defined($strVariableKey))
if ($oCommand->paramTest('variable-key'))
{
$self->{oManifest}->variableSet($strVariableKey, trim($strOutput), true);
$self->{oManifest}->variableSet($oCommand->paramGet('variable-key'), trim($strOutput), true);
}
}
elsif ($$hCacheKey{output})
Expand All @@ -363,9 +363,10 @@ sub execute
}
}

if (defined($strVariableKey) && !defined($self->{oManifest}->variableGet($strVariableKey)))
# Default variable output when it was not set by execution
if ($oCommand->paramTest('variable-key') && !defined($self->{oManifest}->variableGet($oCommand->paramGet('variable-key'))))
{
$self->{oManifest}->variableSet($strVariableKey, '[Test Variable]', true);
$self->{oManifest}->variableSet($oCommand->paramGet('variable-key'), '[Test Variable]', true);
}

# Return from function and log return values if any
Expand Down

0 comments on commit b4ebcdf

Please sign in to comment.