From: Sven Schöling Date: Wed, 21 Jul 2010 16:20:55 +0000 (+0200) Subject: CVar validity ausgelagert in eine Massenfunktion. X-Git-Tag: release-2.6.2beta1~226 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ad2e3220c7da79f7849f6931ed6cdb6e3f497feb;p=kivitendo-erp.git CVar validity ausgelagert in eine Massenfunktion. Reduziert die Anzahl der Datenbankzugriffe bei großen Belegen massiv. --- diff --git a/SL/CVar.pm b/SL/CVar.pm index cdc05b5ab..8ecda7460 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -669,6 +669,28 @@ sub get_custom_variables_validity { return !$invalid; } +sub custom_variables_validity_by_trans_id { + $main::lxdebug->enter_sub(2); + + my $self = shift; + my %params = @_; + + return sub { 0 } unless $params{trans_id}; + + my $myconfig = \%main::myconfig; + my $form = $main::form; + + my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); + + my $query = qq|SELECT config_id, COUNT(*) FROM custom_variables_validity WHERE trans_id = ? GROUP BY config_id|; + + my %invalids = selectall_as_map($form, $dbh, $query, 'config_id', 'count', $params{trans_id}); + + $main::lxdebug->leave_sub(2); + + return sub { !$invalids{+shift} }; +} + 1; __END__ diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 94d536cbd..6a0d2fc40 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -2077,7 +2077,7 @@ sub _update_custom_variables { my $form = $main::form; $form->{CVAR_CONFIGS} ||= { }; - $form->{CVAR_CONFIGS}->{IC} = CVar->get_configs(module => 'IC'); + $form->{CVAR_CONFIGS}->{IC} ||= CVar->get_configs(module => 'IC'); $main::lxdebug->leave_sub(); } @@ -2094,10 +2094,11 @@ sub _render_custom_variables_inputs { return; } + my $valid = CVar->custom_variables_validity_by_trans_id(trans_id => $params{part_id}); + my $num_visible_cvars = 0; foreach my $cvar (@{ $form->{CVAR_CONFIGS}->{IC} }) { - $cvar->{valid} = $params{part_id} && - CVar->get_custom_variables_validity(config_id => $cvar->{id}, trans_id => $params{part_id}); + $cvar->{valid} = $params{part_id} && $valid->($cvar->{id}); my $description = ''; if ($cvar->{flag_editable} && $cvar->{valid}) {