Skip to content

Commit

Permalink
Merge pull request #1398 from ikedas/issue-1186_rev by ikedas
Browse files Browse the repository at this point in the history
Revert changes for #1186 "Improving data source synchronization performance"
  • Loading branch information
ikedas authored May 23, 2022
2 parents 9394a80 + 55f99ac commit 17e1a6e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 287 deletions.
77 changes: 1 addition & 76 deletions src/lib/Sympa/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2021 The Sympa Community. See the
# Copyright 2017, 2018, 2019, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -108,13 +108,6 @@ sub connect {
$self);
return 1;
}
# Disconnected: Transaction (if any) was aborted.
if (delete $self->{_sdbTransactionLevel}) {
$log->syslog('err', 'Transaction on database %s was aborted: %s',
$self, $DBI::errstr);
$self->set_persistent($self->{_sdbPrevPersistency});
return undef;
}

# Do we have required parameters?
foreach my $param (@{$self->required_parameters}) {
Expand Down Expand Up @@ -413,59 +406,6 @@ sub prepare_query_log_values {
# DEPRECATED: Use tools::eval_in_time() and fetchall_arrayref().
#sub fetch();

# As most of DBMS do not support nested transactions, these are not
# effective during when {_sdbTransactionLevel} attribute is
# positive, i.e. only the outermost transaction will be available.
sub begin {
my $self = shift;

$self->{_sdbTransactionLevel} //= 0;
if ($self->{_sdbTransactionLevel}++) {
return 1;
}

my $dbh = $self->__dbh;
return undef unless $dbh;

$dbh->begin_work or die $DBI::errstr;
$self->{_sdbPrevPersistency} = $self->set_persistent(0);
return 1;
}

sub commit {
my $self = shift;

unless ($self->{_sdbTransactionLevel}) {
die 'bug in logic. Ask developer';
}
if (--$self->{_sdbTransactionLevel}) {
return 1;
}

my $dbh = $self->__dbh;
return undef unless $dbh;

$self->set_persistent($self->{_sdbPrevPersistency});
return $dbh->commit;
}

sub rollback {
my $self = shift;

unless ($self->{_sdbTransactionLevel}) {
die 'bug in logic. Ask developer';
}
if (--$self->{_sdbTransactionLevel}) {
return 1;
}

my $dbh = $self->__dbh;
return undef unless $dbh;

$self->set_persistent($self->{_sdbPrevPersistency});
return $dbh->rollback;
}

sub disconnect {
my $self = shift;

Expand Down Expand Up @@ -621,16 +561,6 @@ TBD.
I<Constructor>.
Creates new database instance.
=item begin ( )
I<Instance method>, I<only for SQL>.
Begin transaction.
=item commit ( )
I<Instance method>, I<only for SQL>.
Commit transaction.
=item do_operation ( $operation, options... )
I<Instance method>, I<only for LDAP>.
Expand Down Expand Up @@ -661,11 +591,6 @@ Returns:
Statement handle (L<DBI::st> object or such), or C<undef>.
=item rollback ( )
I<Instance method>, I<only for SQL>.
Rollback transaction.
=back
=head1 SEE ALSO
Expand Down
14 changes: 1 addition & 13 deletions src/lib/Sympa/DatabaseDriver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2018, 2021 The Sympa Community. See the
# Copyright 2018, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -565,14 +565,6 @@ provided by L<Sympa::Database> class:
=over
=item begin ( )
I<Overridable>, I<only for SQL driver>.
=item commit ( )
I<Overridable>, I<only for SQL driver>.
=item do_operation ( $operation, $parameters, ...)
I<Overridable>, I<only for LDAP driver>.
Expand All @@ -585,10 +577,6 @@ I<Overridable>, I<only for SQL driver>.
I<Overridable>, I<only for SQL driver>.
=item rollback ( )
I<Overridable>, I<only for SQL driver>.
=item AS_DOUBLE ( $value )
I<Overridable>.
Expand Down
18 changes: 8 additions & 10 deletions src/lib/Sympa/DatabaseDriver/SQLite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2018, 2021 The Sympa Community. See the
# Copyright 2018, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -521,20 +521,18 @@ sub translate_type {
}

# Note:
# - To prevent "database is locked" error, acquire "immediate" lock
# by each query. Most queries excluding "SELECT" need to lock in this
# manner.
# - If a transaction has been begun, lock is not needed, because SQLite
# does not support nested transactions.
# To prevent "database is locked" error, acquire "immediate" lock
# by each query. Most queries excluding "SELECT" need to lock in this
# manner.
sub do_query {
my $self = shift;
my $sth;
my $rc;

my $need_lock =
($_[0] =~
/^\s*(ALTER|CREATE|DELETE|DROP|INSERT|REINDEX|REPLACE|UPDATE)\b/i)
unless $self->{_sdbTransactionLevel};
/^\s*(ALTER|CREATE|DELETE|DROP|INSERT|REINDEX|REPLACE|UPDATE)\b/i
);

## acquire "immediate" lock
unless (!$need_lock or $self->__dbh->begin_work) {
Expand Down Expand Up @@ -573,8 +571,8 @@ sub do_prepared_query {

my $need_lock =
($_[0] =~
/^\s*(ALTER|CREATE|DELETE|DROP|INSERT|REINDEX|REPLACE|UPDATE)\b/i)
unless $self->{_sdbTransactionLevel};
/^\s*(ALTER|CREATE|DELETE|DROP|INSERT|REINDEX|REPLACE|UPDATE)\b/i
);

## acquire "immediate" lock
unless (!$need_lock or $self->__dbh->begin_work) {
Expand Down
34 changes: 1 addition & 33 deletions src/lib/Sympa/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 GIP RENATER
# Copyright 2017, 2018, 2019, 2020, 2021 The Sympa Community. See the
# Copyright 2017, 2018, 2019, 2020, 2021, 2022 The Sympa Community. See the
# AUTHORS.md file at the top-level directory of this distribution and at
# <https://github.com/sympa-community/sympa.git>.
#
Expand Down Expand Up @@ -1551,8 +1551,6 @@ sub delete_list_member {
my $sdm = Sympa::DatabaseManager->instance;
my $sth;

$sdm->begin;

foreach my $who (@$users) {
next unless defined $who and length $who;
$who = Sympa::Tools::Text::canonic_email($who);
Expand Down Expand Up @@ -1618,12 +1616,6 @@ sub delete_list_member {
$total--;
}

unless ($sdm->commit) {
$log->syslog('err', 'Error at delete member commit: %s', $sdm->error);
$sdm->rollback;
return 0;
}

$self->_cache_publish_expiry('member');

return (-1 * $total);
Expand All @@ -1644,8 +1636,6 @@ sub delete_list_admin {
my $sdm = Sympa::DatabaseManager->instance;
my $sth;

$sdm->begin;

$users = [$users] unless ref $users; # compat.
foreach my $who (@$users) {
next unless defined $who and length $who;
Expand Down Expand Up @@ -1683,12 +1673,6 @@ sub delete_list_admin {
$total--;
}

unless ($sdm->commit) {
$log->syslog('err', 'Error at add member commit: %s', $sdm->error);
$sdm->rollback;
return 0;
}

$self->_cache_publish_expiry('admin_user');

return (-1 * $total);
Expand Down Expand Up @@ -3111,7 +3095,6 @@ sub add_list_member {
my %map_field = _map_list_member_cols();

my $sdm = Sympa::DatabaseManager->instance;
$sdm->begin;

foreach my $u (@users) {
unless (Sympa::Tools::Text::valid_email($u->{email})) {
Expand Down Expand Up @@ -3301,11 +3284,6 @@ sub add_list_member {
$current_list_members_count++;
}

unless ($sdm->commit) {
$log->syslog('err', 'Error at add member commit: %s', $sdm->error);
$sdm->rollback;
}

$self->_cache_publish_expiry('member');

push @$stash_ref, ['notice', 'add_performed', {total => $added_members}]
Expand All @@ -3331,20 +3309,10 @@ sub add_list_admin {
my $stash_ref = $options{stash} || [];

my $total = 0;

my $sdm = Sympa::DatabaseManager->instance;
$sdm->begin;

foreach my $user (@users) {
$total++ if $self->_add_list_admin($role, $user, %options);
}

unless ($sdm->commit) {
$log->syslog('err', 'Error at add admin commit: %s', $sdm->error);
$sdm->rollback;
return 0;
}

$self->_cache_publish_expiry('admin_user') if $total;

push @$stash_ref, ['notice', 'add_performed', {total => $total}]
Expand Down
Loading

0 comments on commit 17e1a6e

Please sign in to comment.