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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2020-01-23 10:20:31 +00:00 committed by Joy Nelson
parent 6ff3be60ae
commit b86a98dffd
1 changed files with 7 additions and 17 deletions

View File

@ -30,7 +30,7 @@ B<compare_es_to_db.pl>
=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;
my @es_problems;
foreach my $problem ( sort { $a <=> $b } @diff){
if ( (grep /^$problem$/, @db_records) ){
push @koha_problems, $problem;
} else {
push @es_problems, $problem;
}
}
my @koha_problems = sort { $a <=> $b } array_minus(@db_records, @es_ids);
my @es_problems = sort { $a <=> $b } array_minus(@es_ids, @db_records);
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";