From b26576bfa8ceb6687e9fda1d31a254dbcb961c40 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Thu, 17 Dec 2020 10:06:53 +0100 Subject: [PATCH] marsadm: speedup template file reading --- userspace/marsadm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/userspace/marsadm b/userspace/marsadm index 68a45eaa..36ee2998 100755 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -559,6 +559,8 @@ my %member_peers; my %guest_peers; my %any_peers; +my %file_info; + my $cache_dir = "$mars/cache-$real_host"; sub __read_cache { @@ -734,6 +736,7 @@ sub _scan_caches { sub _reset_resources { system("rm -rf $cache_dir/*.cache"); %total_peers = (); + %file_info = (); } sub is_member { @@ -1158,6 +1161,10 @@ sub _make_var_name { sub _get_file { my ($filename) = @_; + my $cached = $file_info{$filename}; + if ($cached) { + return @$cached; + } my $IN; local $/; # slurp if (!open($IN, "<", $filename)) { @@ -1167,6 +1174,7 @@ sub _get_file { my $mtime = get_stamp($IN); my $text = <$IN>; close($IN); + $file_info{$filename} = [$mtime, $text]; return ($mtime, $text); }