Commit e8d1afb2 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

wip(frontend): nodes status cache timeout

parent 9e464709
......@@ -877,6 +877,7 @@ sub list_requests($self, $id_domain_req=undef, $seconds=60) {
next if $command eq 'enforce_limits'
|| $command eq 'refresh_vms'
|| $command eq 'refresh_storage'
|| $command eq 'refresh_machine'
|| $command eq 'ping_backend'
|| $command eq 'cleanup'
|| $command eq 'screenshot'
......
......@@ -39,6 +39,8 @@ our $CONFIG = \$Ravada::CONFIG;
our $MIN_MEMORY_MB = 128 * 1024;
our $SSH_TIMEOUT = 20 * 1000;
our $CACHE_TIMEOUT = 60;
our $FIELD_TIMEOUT = '_data_timeout';
our %VM; # cache Virtual Manager Connection
our %SSH;
......@@ -690,6 +692,7 @@ sub _data($self, $field, $value=undef) {
# _init_connector();
$self->_timed_data_cache() if $self->{_data}->{$field} && $field ne 'name';
return $self->{_data}->{$field} if exists $self->{_data}->{$field};
return if !$self->store();
......@@ -701,6 +704,15 @@ sub _data($self, $field, $value=undef) {
return $self->{_data}->{$field};
}
sub _timed_data_cache($self) {
return if time - $self->{$FIELD_TIMEOUT} < $CACHE_TIMEOUT;
my $name = $self->{_data}->{name};
my $id = $self->{_data}->{id};
delete $self->{_data};
$self->{_data}->{name} = $name if $name;
$self->{_data}->{id} = $id if $id;
}
sub _do_select_vm_db {
my $self = shift;
my %args = @_;
......@@ -734,6 +746,7 @@ sub _select_vm_db {
my ($row) = ($self->_do_select_vm_db(@_) or $self->_insert_vm_db(@_));
$self->{_data} = $row;
$self->{$FIELD_TIMEOUT} = time if $row->{id};
return $row if $row->{id};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment