Skip to content

Commit

Permalink
add some profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jul 11, 2023
1 parent 8fd1f15 commit 4f40781
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Thruk/Controller/main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,26 @@ sub _get_notifications {
##########################################################
sub _notifications_data {
my($c, $start) = @_;
$c->stats->profile(begin => "_notifications_data read cache");

my $cache = Thruk::Utils::Cache->new($c->config->{'var_path'}.'/notifications.cache');
my $cached = $cache->get("notifications") || {};

$c->stats->profile(end => "_notifications_data read cache");

# update cache every 60sec
my $age = $cache->age();
$c->stash->{'notifications_age'} = defined $age ? $age : "";
if(!defined $age || $age > 50) {
$c->stats->profile(begin => "_notifications_data bg refresh");
$cache->touch(); # update timestamp to avoid multiple parallel updates
require Thruk::Utils::External;
my $job = Thruk::Utils::External::perl($c, {
expr => 'Thruk::Controller::main::_notifications_update_cache($c, '.$start.')',
background => 1,
clean => 1,
});
$c->stats->profile(end => "_notifications_data bg refresh");
}

return($cached);
Expand Down

0 comments on commit 4f40781

Please sign in to comment.