From 56fcf5a34d580026e0799baf07b537ac5bc43bb5 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 23 Jan 2020 10:20:31 +0000 Subject: [PATCH] Bug 22831: (RM follow-up) Code golf Rather than performing a symmetric diff and then splitting the results in a further loop this patch changes to logic to use two asymetric diffs to get the results more directly. Signed-off-by: Martin Renvoize --- misc/maintenance/compare_es_to_db.pl | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/misc/maintenance/compare_es_to_db.pl b/misc/maintenance/compare_es_to_db.pl index 35d391b66b..ee5473b646 100644 --- a/misc/maintenance/compare_es_to_db.pl +++ b/misc/maintenance/compare_es_to_db.pl @@ -30,7 +30,7 @@ B =cut use Modern::Perl; -use Array::Utils qw( array_diff ); +use Array::Utils qw( array_minus ); use C4::Context; @@ -76,29 +76,18 @@ foreach my $index ( ('biblios','authorities') ){ push @es_ids, $doc->{_id}; $i++; } - print "\nComparing arrays, this may take a while\n"; - - # And compare the arrays - # array_diff returns only a list of values which are not common to both arrays - my @diff = array_diff(@db_records, @es_ids ); - - print "All records match\n" unless @diff; # Fetch values for providing record links my $es_params = $searcher->get_elasticsearch_params; my $es_base = "$es_params->{nodes}[0]/$es_params->{index_name}"; my $opac_base = C4::Context->preference('OPACBaseURL'); + print "\nComparing arrays, this may take a while\n"; + + my @koha_problems = sort { $a <=> $b } array_minus(@db_records, @es_ids); + my @es_problems = sort { $a <=> $b } array_minus(@es_ids, @db_records); - my @koha_problems; - my @es_problems; - foreach my $problem ( sort { $a <=> $b } @diff){ - if ( (grep /^$problem$/, @db_records) ){ - push @koha_problems, $problem; - } else { - push @es_problems, $problem; - } - } + print "All records match\n" unless ( @koha_problems || @es_problems ); if ( @koha_problems ){ print "=================\n"; @@ -113,6 +102,7 @@ foreach my $index ( ('biblios','authorities') ){ } } } + if ( @es_problems ){ print "=================\n"; print "Records that exist in ES but not in Koha\n"; -- 2.39.5