Author: msergeant
Date: Fri Nov 16 06:51:01 2007
New Revision: 813

Modified:
   trunk/lib/Qpsmtpd.pm

Log:
Implement config caching properly (for async).


Modified: trunk/lib/Qpsmtpd.pm
==============================================================================
--- trunk/lib/Qpsmtpd.pm        (original)
+++ trunk/lib/Qpsmtpd.pm        Fri Nov 16 06:51:01 2007
@@ -5,7 +5,10 @@
 use Sys::Hostname;
 use Qpsmtpd::Constants;
 
-$VERSION = "0.42rc1";
+$VERSION = "0.40-dev";
+
+my $hooks = {};
+my $_config_cache = {};
 
 sub version { $VERSION };
 
@@ -119,8 +122,12 @@
    }
 }
 
+my %config_dir_memo;
 sub config_dir {
   my ($self, $config) = @_;
+  if (exists $config_dir_memo{$config}) {
+      return $config_dir_memo{$config};
+  }
   my $configdir = ($ENV{QMAIL} || '/var/qmail') . '/control';
   my ($path) = ($ENV{PROCESS} ? $ENV{PROCESS} : $0) =~ m!(.*?)/([^/]+)$!;
   $configdir = "$path/config" if (-e "$path/config/$config");
@@ -128,7 +135,7 @@
     $ENV{QPSMTPD_CONFIG} =~ /^(.*)$/; # detaint
     $configdir = $1 if -e "$1/$config";
   }
-  return $configdir;
+  return $config_dir_memo{$config} = $configdir;
 }
 
 sub plugin_dirs {
@@ -145,8 +152,8 @@
 sub get_qmail_config {
   my ($self, $config, $type) = @_;
   $self->log(LOGDEBUG, "trying to get config for $config");
-  if ($self->{_config_cache}->{$config}) {
-    return wantarray ? @{$self->{_config_cache}->{$config}} : 
$self->{_config_cache}->{$config}->[0];
+  if ($_config_cache->{$config}) {
+    return wantarray ? @{$_config_cache->{$config}} : 
$_config_cache->{$config}->[0];
   }
   my $configdir = $self->config_dir($config);
 
@@ -223,7 +230,7 @@
     }
   }
 
-  $self->{_config_cache}->{$config} = [EMAIL PROTECTED];
+  $_config_cache->{$config} = [EMAIL PROTECTED];
 
   return wantarray ? @config : $config[0];
 }
@@ -239,7 +246,7 @@
 
     if (opendir(INCD, $inclusion)) {
       @includes = map { "$inclusion/$_" }
-        (grep { -f "$inclusion/$_" and !/^\./ } readdir INCD);
+        (grep { -f "$inclusion/$_" and !/^\./ } sort readdir INCD);
       closedir INCD;
     } else {
       $self->log(LOGERROR, "Couldn't open directory $inclusion,".

Reply via email to