Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] [sympa-commits] r12800 - in branches/sympa-6.2-branch/src: lib/Sympa sbin

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: David Verdin <address@concealed>
  • To: address@concealed
  • Subject: Re: [sympa-developpers] [sympa-commits] r12800 - in branches/sympa-6.2-branch/src: lib/Sympa sbin
  • Date: Wed, 18 May 2016 10:23:45 +0200

You know what Soji ? Sometimes, you solve issues so easily that I feel dumb not  to have thought about it before...:-P


Le 14/05/2016 à 11:04, address@concealed a écrit :
Author: sikeda
Date: 2016-05-14 09:04:47 +0000 (Sat, 14 May 2016)
New Revision: 12800

Modified:
   branches/sympa-6.2-branch/src/lib/Sympa/DatabaseDescription.pm
   branches/sympa-6.2-branch/src/lib/Sympa/List.pm
   branches/sympa-6.2-branch/src/sbin/sympa.pl.in
Log:
[bug] [Reported by S. Rich, Duke univ.] Close List operation cause timeout on web interface.  Because Sympa scans all lists to ensure that any lists do never include the list to be closed.
Fixed by introducing new DB table 'inclusion_table' to cache 'include_list' configuration of lists.  The new table will be created and filled automatically during upgrade process.


Modified: branches/sympa-6.2-branch/src/lib/Sympa/DatabaseDescription.pm
===================================================================
--- branches/sympa-6.2-branch/src/lib/Sympa/DatabaseDescription.pm	2016-05-14 08:49:30 UTC (rev 12799)
+++ branches/sympa-6.2-branch/src/lib/Sympa/DatabaseDescription.pm	2016-05-14 09:04:47 UTC (rev 12800)
@@ -418,6 +418,46 @@
             'Exclusion table is used in order to manage unsubscription for subsceriber inclued from an external data source.',
         'order' => 5,
     },
+    'inclusion_table' => {
+        'fields' => {
+            'list_inclusion' => {
+                'struct' => $list_struct,
+                'doc'      => 'list name of including list',
+                'order'    => 1,
+                'primary'  => 1,
+                'not_null' => 1,
+            },
+            'robot_inclusion' => {
+                'struct'   => $robot_struct,
+                'doc'      => 'robot (domain) name of the list',
+                'order'    => 2,
+                'primary'  => 1,
+                'not_null' => 1,
+            },
+            'included_list_inclusion' => {
+                'struct' => $list_struct,
+                'doc'      => 'list name of included list',
+                'order'    => 4,
+                'primary'  => 1,
+                'not_null' => 1,
+            },
+            'included_robot_inclusion' => {
+                'struct'   => $robot_struct,
+                'doc'      => 'robot (domain) name of included list',
+                'order'    => 5,
+                'primary'  => 1,
+                'not_null' => 1,
+            },
+            'update_epoch_inclusion' => {
+                'struct' => 'int(11)',
+                'doc'    => 'the date this entry was created or updated',
+                'order'  => 6,
+            },
+        },
+        'doc' =>
+            'Inclusion table is used in order to manage lists inclued from / including subscribers of other lists.',
+        'order' => 4,
+    },
     'session_table' => {
         'fields' => {
             'id_session' => {

Modified: branches/sympa-6.2-branch/src/lib/Sympa/List.pm
===================================================================
--- branches/sympa-6.2-branch/src/lib/Sympa/List.pm	2016-05-14 08:49:30 UTC (rev 12799)
+++ branches/sympa-6.2-branch/src/lib/Sympa/List.pm	2016-05-14 09:04:47 UTC (rev 12800)
@@ -268,6 +268,10 @@
 Returns true is the list is configured to keep archives of
 its messages, i.e. process_archive parameter is set to "on".
 
+=item is_included ( )
+
+Returns true value if the list is included in another list(s).
+
 =item get_stats ( OPTION )
 
 Returns either a formatted printable strings or an array whith
@@ -4408,6 +4412,29 @@
         'on');
 }
 
+sub is_included {
+    my $self = shift;
+
+    my $sdm = Sympa::DatabaseManager->instance;
+    my $sth;
+
+    unless ($sdm
+        and $sth = $sdm->do_prepared_query(
+            q{SELECT COUNT(*)
+              FROM inclusion_table
+              WHERE included_list_inclusion = ? AND
+                    included_robot_inclusion = ?},
+            $self->{'name'}, $self->{'domain'})) {
+        $log->syslog('err', 'Failed to get inclusion information on list %s',
+            $self);
+        return 1; # Fake positive result.
+    }
+    my ($num) = $sth->fetchrow_array;
+    $sth->finish;
+
+    return $num;
+}
+
 # Old name: Sympa::List::get_nextdigest().
 # Moved to Sympa::Spindle::ProcessDigest::_may_distribute_digest().
 #sub may_distribute_digest;
@@ -9189,23 +9216,10 @@
     ## If list is included by another list, then it cannot be removed
     ## TODO : we should also check owner_include and editor_include, but a bit
     ## more tricky
-    my $all_lists = get_lists('*');
-    foreach my $list (@{$all_lists}) {
-        my $included_lists = $list->{'admin'}{'include_list'};
-        next unless (defined $included_lists);
-
-        foreach my $included_list_name (@{$included_lists}) {
-
-            if ($included_list_name eq $self->get_list_id()
-                || (   $included_list_name eq $self->{'name'}
-                    && $list->{'domain'} eq $self->{'domain'})
-                ) {
-                $log->syslog('err',
-                    'List %s is included by list %s: cannot close it',
-                    $self->get_list_id(), $list->get_list_id());
-                return undef;
-            }
-        }
+    if ($self->is_included) {
+        $log->syslog('err',
+            'List %s is included by other list: cannot close it', $self);
+        return undef;
     }
 
     ## Dump subscribers, unless list is already closed
@@ -9750,6 +9764,43 @@
         return undef;
     }
 
+    # Update inclusion_table: This feature was added on 6.2.16.
+    my $now = time;
+    foreach my $l (@{$self->{'admin'}{'include_list'} || []}) {
+        $l =~ s/\s+filter\s+.+//;
+        my ($name, $domain) = map { lc $_ } split /\@/, $l, 2;
+        $domain ||= $self->{'domain'};
+
+        unless (
+            $sth = $sdm->do_prepared_query(
+                q{UPDATE inclusion_table
+                  SET update_epoch_inclusion = ?
+                  WHERE list_inclusion = ? AND robot_inclusion = ? AND
+                        included_list_inclusion = ? AND
+                        included_robot_inclusion = ? AND
+                        (update_epoch_inclusion IS NULL OR
+                         update_epoch_inclusion < ?)},
+            $now, $self->{'name'}, $self->{'domain'}, $name, $domain, $now)
+            and $sth->rows
+            or $sth = $sdm->do_prepared_query(
+                q{INSERT INTO inclusion_table
+                  (list_inclusion, robot_inclusion,
+                   included_list_inclusion, included_robot_inclusion,
+                   update_epoch_inclusion)
+                  VALUES (?, ?, ?, ?, ?)},
+                $self->{'name'}, $self->{'domain'}, $name, $domain, $now)
+            and $sth->rows) {
+            $log->syslog('err', 'Unable to update list %s in database', $self);
+            $sth = pop @sth_stack;
+            return undef;
+        }
+    }
+    $sdm->do_prepared_query(
+        q{DELETE FROM inclusion_table
+          WHERE list_inclusion = ? AND robot_inclusion = ? AND
+                update_epoch_inclusion < ?},
+        $self->{'name'}, $self->{'domain'}, $now);
+
     $sth = pop @sth_stack;
 
     return 1;

Modified: branches/sympa-6.2-branch/src/sbin/sympa.pl.in
===================================================================
--- branches/sympa-6.2-branch/src/sbin/sympa.pl.in	2016-05-14 08:49:30 UTC (rev 12799)
+++ branches/sympa-6.2-branch/src/sbin/sympa.pl.in	2016-05-14 09:04:47 UTC (rev 12800)
@@ -967,10 +967,6 @@
 }
 ##########################################
 elsif ($main::options{'sync_list_db'}) {
-    unless ($Conf::Conf{'db_list_cache'} eq 'on') {
-        print STDOUT "\nSympa not configured to use database list caching \n";
-        exit 1;
-    }
     my $listname = $main::options{'list'} || '';
     if (length($listname) > 1) {
         my $list = Sympa::List->new($listname);


--
A bug in Sympa? Quick! To the bug tracker!

 
David Verdin
Études et projets applicatifs
 
Tél : +33 2 23 23 69 71
Fax : +33 2 23 23 71 21
 
www.renater.fr
RENATER
263 Avenue du Gal Leclerc
35042 Rennes Cedex



PNG image

Attachment: smime.p7s
Description: Signature cryptographique S/MIME




Archive powered by MHonArc 2.6.19+.

Top of Page