From 3063b9a83fbf516b55feebb66c2fdc8d3c349944 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 11 Jan 2013 16:03:55 +0100 Subject: [PATCH] PartImport: check_existing etwas optimiert, spart bei Testimports gut 40% Zeit. --- SL/Controller/CsvImport.pm | 2 +- SL/Controller/CsvImport/Base.pm | 6 ++++-- SL/Controller/CsvImport/Part.pm | 34 ++++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index 89bf33c2b..e38eb655c 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -305,7 +305,7 @@ sub test_and_import { my $worker = $self->worker(); - $worker->run; + $worker->run(%params); return if $self->errors; diff --git a/SL/Controller/CsvImport/Base.pm b/SL/Controller/CsvImport/Base.pm index 1c2f4c3f1..185c7adde 100644 --- a/SL/Controller/CsvImport/Base.pm +++ b/SL/Controller/CsvImport/Base.pm @@ -15,12 +15,14 @@ use parent qw(Rose::Object); use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(controller file csv save_with_cascade) ], + scalar => [ qw(controller file csv test_run save_with_cascade) ], 'scalar --get_set_init' => [ qw(profile displayable_columns existing_objects class manager_class cvar_columns all_cvar_configs all_languages payment_terms_by all_vc vc_by) ], ); sub run { - my ($self) = @_; + my ($self, %params) = @_; + + $self->test_run($params{test_run}); $self->controller->track_progress(phase => 'parsing csv', progress => 0); diff --git a/SL/Controller/CsvImport/Part.pm b/SL/Controller/CsvImport/Part.pm index 5529082ff..2ca12300a 100644 --- a/SL/Controller/CsvImport/Part.pm +++ b/SL/Controller/CsvImport/Part.pm @@ -4,6 +4,7 @@ use strict; use SL::Helper::Csv; +use SL::DBUtils; use SL::DB::Buchungsgruppe; use SL::DB::CustomVariable; use SL::DB::CustomVariableConfig; @@ -60,13 +61,19 @@ sub init_units_by { sub init_parts_by { my ($self) = @_; - my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } }, - partnumber => { part => { }, - service => { } } }; - - foreach my $part (@{ $self->existing_objects }) { - next if $part->assembly; - $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part; +# my $parts_by = { id => { map { ( $_->id => $_ ) } grep { !$_->assembly } @{ $self->existing_objects } }, +# partnumber => { part => { }, +# service => { } } }; +# +# foreach my $part (@{ $self->existing_objects }) { +# next if $part->assembly; +# $parts_by->{partnumber}->{ $part->type }->{ $part->partnumber } = $part; +# } + + my $parts_by = {}; + my $sth = prepare_execute_query($::form, $::form->get_standard_dbh, 'SELECT partnumber FROM parts'); + while (my ($partnumber) = $sth->fetchrow_array()) { + $parts_by->{partnumber}{$partnumber} = 1; } return $parts_by; @@ -196,12 +203,17 @@ sub check_existing { my $object = $entry->{object}; - $entry->{part} = SL::DB::Manager::Part->find_by( - SL::DB::Manager::Part->type_filter($object->type), - ( partnumber => $object->partnumber ) x!! $object->partnumber, - ); + if (!$self->test_run && $object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) { + $entry->{part} = SL::DB::Manager::Part->find_by( + SL::DB::Manager::Part->type_filter($object->type), + ( partnumber => $object->partnumber ) x!! $object->partnumber, + ); + } if ($self->settings->{article_number_policy} eq 'update_prices') { + if ($object->partnumber && $self->parts_by->{partnumber}{$object->partnumber}) { + push @{ $entry->{information} }, $::locale->text('Updating prices of existing entry in database'); + } if ($entry->{part}) { map { $entry->{part}->$_( $object->$_ ) if defined $object->$_ } qw(sellprice listprice lastcost); -- 2.20.1