Skip to content

Commit

Permalink
edit_list.conf was loaded multiple times and wasted memory (sympa-com…
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas committed May 13, 2021
1 parent 39e3006 commit 1acfce1
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/lib/Sympa/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ foreach my $t (qw(subscriber_table admin_table)) {
# This is the generic hash which keeps all lists in memory.
my %list_of_lists = ();

my %all_edit_list = ();

## Creates an object.
sub new {
my ($pkg, $name, $robot, $options) = @_;
Expand Down Expand Up @@ -182,8 +184,7 @@ sub new {
return undef;
}

$list->_load_edit_list_conf(
reload_config => ($options->{reload_config} || $status));
$list->_load_edit_list_conf;

return $list;
}
Expand Down Expand Up @@ -3566,7 +3567,8 @@ sub may_edit {
$parameter = 'info.file' if $parameter eq 'info';
}

my $edit_list_conf = $self->{_edit_list};
my $edit_list_conf = $all_edit_list{$self->{_edit_list}}->{_conf};
die 'bug in logic. Ask developer' unless $edit_list_conf;

my $role;

Expand Down Expand Up @@ -6148,9 +6150,8 @@ sub _flush_list_db {
# Return a hash from the edit_list_conf file.
# Old name: tools::load_edit_list_conf().
sub _load_edit_list_conf {
$log->syslog('debug2', '(%s, %s => %s)', @_);
my $self = shift;
my %options = @_;
$log->syslog('debug2', '(%s)', @_);
my $self = shift;

my $robot = $self->{'domain'};

Expand All @@ -6159,23 +6160,22 @@ sub _load_edit_list_conf {
%Sympa::ListDef::user_info
};

# Load edit_list.conf: Track by file, not domain (file may come from
# server, robot, family or list context).
my $last_path_config = $self->{_path}{edit_list} // '';
my $path_config = Sympa::search_fullpath($self, 'edit_list.conf');
my $last_mtime_config = $self->{_mtime}{edit_list} // POSIX::INT_MIN();
my $mtime_config = Sympa::Tools::File::get_mtime($path_config);
# Load edit_list.conf: Track by file, not list or domain.
my $path = Sympa::search_fullpath($self, 'edit_list.conf');
my $last_mtime = ($all_edit_list{$path} // {})->{_mtime};
my $mtime = Sympa::Tools::File::get_mtime($path);
$self->{_edit_list} = $path;
return
unless $options{reload_config}
or not $self->{_edit_list}
or $last_path_config ne $path_config
or $last_mtime_config < $mtime_config;
if ($all_edit_list{$path} // {})->{_conf}
and $last_mtime == $mtime;

my $fh;
unless (open $fh, '<', $path_config) {
$log->syslog('err', 'Unable to open config file %s: %m',
$path_config);
$self->{_edit_list} = {};
unless (open $fh, '<', $path) {
$log->syslog('err', 'Unable to open config file %s: %m', $path);
$all_edit_list{$path} = {
_conf => {},
_mtime => $mtime,
};
return;
}

Expand Down Expand Up @@ -6228,21 +6228,21 @@ sub _load_edit_list_conf {
}
} else {
$log->syslog('info', 'Unknown parameter in %s (Ignored): %s',
$path_config, $line);
$path, $line);
next;
}
}

if ($error_in_conf) {
Sympa::send_notify_to_listmaster($robot, 'edit_list_error',
[$path_config]);
Sympa::send_notify_to_listmaster($robot, 'edit_list_error', [$path]);
}

close $fh;

$self->{_path}{edit_list} = $path_config;
$self->{_mtime}{edit_list} = $mtime_config;
$self->{_edit_list} = $conf;
$all_edit_list{$path} = {
_conf => $conf,
_mtime => $mtime,
};
}

###### END of the List package ######
Expand Down

0 comments on commit 1acfce1

Please sign in to comment.