Unverified Commit 8d21112b authored by IKEDA Soji's avatar IKEDA Soji Committed by GitHub
Browse files

Merge pull request #1172 from ikedas/issue-1170 by ikedas

edit_list.conf should not be loaded multiple times to waste memory (an item of #584)
parents 04d0ffb7 1230f3d6
...@@ -101,6 +101,8 @@ foreach my $t (qw(subscriber_table admin_table)) { ...@@ -101,6 +101,8 @@ foreach my $t (qw(subscriber_table admin_table)) {
# This is the generic hash which keeps all lists in memory. # This is the generic hash which keeps all lists in memory.
my %list_of_lists = (); my %list_of_lists = ();
my %all_edit_list = ();
## Creates an object. ## Creates an object.
sub new { sub new {
my ($pkg, $name, $robot, $options) = @_; my ($pkg, $name, $robot, $options) = @_;
...@@ -182,8 +184,7 @@ sub new { ...@@ -182,8 +184,7 @@ sub new {
return undef; return undef;
} }
$list->_load_edit_list_conf( $list->_load_edit_list_conf;
reload_config => ($options->{reload_config} || $status));
return $list; return $list;
} }
...@@ -3522,7 +3523,8 @@ sub may_edit { ...@@ -3522,7 +3523,8 @@ sub may_edit {
$parameter = 'info.file' if $parameter eq 'info'; $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; my $role;
...@@ -6075,34 +6077,32 @@ sub _flush_list_db { ...@@ -6075,34 +6077,32 @@ sub _flush_list_db {
# Return a hash from the edit_list_conf file. # Return a hash from the edit_list_conf file.
# Old name: tools::load_edit_list_conf(). # Old name: tools::load_edit_list_conf().
sub _load_edit_list_conf { sub _load_edit_list_conf {
$log->syslog('debug2', '(%s, %s => %s)', @_); $log->syslog('debug2', '(%s)', @_);
my $self = shift; my $self = shift;
my %options = @_;
my $robot = $self->{'domain'}; my $robot = $self->{'domain'};
my $pinfo = { my $pinfo = {
%{Sympa::Robot::list_params($self->{'domain'})}, %Sympa::ListDef::pinfo,
%Sympa::ListDef::user_info %Sympa::ListDef::user_info
}; };
# Load edit_list.conf: Track by file, not domain (file may come from # Load edit_list.conf: Track by file, not list or domain.
# server, robot, family or list context). my $path = Sympa::search_fullpath($self, 'edit_list.conf');
my $last_path_config = $self->{_path}{edit_list} // ''; my $last_mtime = ($all_edit_list{$path} // {})->{_mtime};
my $path_config = Sympa::search_fullpath($self, 'edit_list.conf'); my $mtime = Sympa::Tools::File::get_mtime($path);
my $last_mtime_config = $self->{_mtime}{edit_list} // POSIX::INT_MIN(); $self->{_edit_list} = $path;
my $mtime_config = Sympa::Tools::File::get_mtime($path_config);
return return
unless $options{reload_config} if ($all_edit_list{$path} // {})->{_conf}
or not $self->{_edit_list} and $last_mtime == $mtime;
or $last_path_config ne $path_config
or $last_mtime_config < $mtime_config;
my $fh; my $fh;
unless (open $fh, '<', $path_config) { unless (open $fh, '<', $path) {
$log->syslog('err', 'Unable to open config file %s: %m', $log->syslog('err', 'Unable to open config file %s: %m', $path);
$path_config); $all_edit_list{$path} = {
$self->{_edit_list} = {}; _conf => {},
_mtime => $mtime,
};
return; return;
} }
...@@ -6155,21 +6155,21 @@ sub _load_edit_list_conf { ...@@ -6155,21 +6155,21 @@ sub _load_edit_list_conf {
} }
} else { } else {
$log->syslog('info', 'Unknown parameter in %s (Ignored): %s', $log->syslog('info', 'Unknown parameter in %s (Ignored): %s',
$path_config, $line); $path, $line);
next; next;
} }
} }
if ($error_in_conf) { if ($error_in_conf) {
Sympa::send_notify_to_listmaster($robot, 'edit_list_error', Sympa::send_notify_to_listmaster($robot, 'edit_list_error', [$path]);
[$path_config]);
} }
close $fh; close $fh;
$self->{_path}{edit_list} = $path_config; $all_edit_list{$path} = {
$self->{_mtime}{edit_list} = $mtime_config; _conf => $conf,
$self->{_edit_list} = $conf; _mtime => $mtime,
};
} }
###### END of the List package ###### ###### END of the List package ######
......
Markdown is supported
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