Skip to content

Commit

Permalink
Indices: cache the current results from each sub
Browse files Browse the repository at this point in the history
These are cleared as we go to avoid leakage.
  • Loading branch information
shawnlaffan committed Feb 24, 2024
1 parent 4168546 commit b2ee3ed
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Biodiverse/Indices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1533,11 +1533,16 @@ sub run_dependencies {
my $tmp = $self->get_param('AS_RESULTS_FROM_GLOBAL') || {};
my %as_results_from_global = %$tmp; # make a copy

state $cache_name_local_results = 'AS_RESULTS_FROM_LOCAL';

# Now we run the calculations at this level.
# We also keep track of what has been run
# to avoid repetition through multiple dependencies.
my %results;
my %as_results_from;
# make sure this is new each iteration
$self->set_cached_value ($cache_name_local_results => \%as_results_from);

foreach my $calc (@$calc_list) {
my $calc_results;

Expand Down Expand Up @@ -1574,6 +1579,9 @@ sub run_dependencies {
$results{$calc} = $calc_results;
}

# We refresh each call above, but this ensures last one is cleaned up.
$self->delete_cached_value($cache_name_local_results);

if ( $type eq 'pre_calc_global' ) {
$self->set_param( AS_RESULTS_FROM_GLOBAL => \%as_results_from_global );
}
Expand Down

0 comments on commit b2ee3ed

Please sign in to comment.