use strict;
use warnings;
+use File::stat ();
use PVE::Tools qw(extract_param);
use PVE::SafeSyslog;
use PVE::RESTHandler;
use PVE::RPCEnvironment;
+use JSON;
use PVE::JSONSchema qw(get_standard_option);
use AptPkg::Cache;
code => sub {
my ($param) = @_;
+ # we try to cache results
+ my $pve_pkgstatus_fn = "/var/lib/pve-manager/pkgupdates";
+
+ if (my $st1 = File::stat::stat($pve_pkgstatus_fn)) {
+ my $st2 = File::stat::stat("/var/cache/apt/pkgcache.bin");
+ my $st3 = File::stat::stat("/var/lib/dpkg/status");
+
+ if ($st2->mtime < $st1->mtime && $st3->mtime < $st1->mtime) {
+ my $data;
+ eval {
+ my $jsonstr = PVE::Tools::file_get_contents($pve_pkgstatus_fn, 5*1024*1024);
+ $data = decode_json($jsonstr);
+ };
+ if (my $err = $@) {
+ warn "error readin cached package status in $pve_pkgstatus_fn\n";
+ # continue and overwrite cache with new content
+ } else {
+ return $data;
+ }
+ }
+ }
+
my $pkglist = [];
my $cache = &$get_apt_cache();
}
}
+ PVE::Tools::file_set_contents($pve_pkgstatus_fn, encode_json($pkglist));
+
return $pkglist;
}});