Skip to content

Commit

Permalink
Merge pull request #1168 from metacpan/haarg/fix-author-indexing
Browse files Browse the repository at this point in the history
fix author indexing
  • Loading branch information
haarg authored Feb 23, 2024
2 parents 256111b + bdf34ef commit 333322d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
16 changes: 14 additions & 2 deletions lib/MetaCPAN/Script/Author.pm
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ sub index_authors {

my $scroll = $self->es->scroll_helper(
index => $self->index->name,
type => 'author',
search_type => 'scan',
size => 500,
body => {
Expand Down Expand Up @@ -224,8 +225,19 @@ sub update_author {
return;
}

return
unless diff_struct( $current_data, $data );
if ( my $diff = diff_struct( $current_data, $data ) ) {

# log a sampling of differences
if ( $self->has_surrogate_keys_to_purge % 10 == 9 ) {
Dlog_debug {
"Found difference in $pauseid: $_"
}
$diff;
}
}
else {
return;
}

$data->{updated} = DateTime->now( time_zone => 'UTC' )->iso8601;

Expand Down
26 changes: 15 additions & 11 deletions lib/MetaCPAN/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -163,34 +163,38 @@ sub single_valued_arrayref_to_scalar {
}

sub diff_struct {
my (@queue) = [@_];
my ( $old_root, $new_root, $allow_extra ) = @_;
my (@queue) = [ $old_root, $new_root, '', $allow_extra ];

while ( my $check = shift @queue ) {
my ( $old, $new, $allow_extra ) = @$check;
my ( $old, $new, $path, $allow_extra ) = @$check;
if ( !defined $new ) {
return !!1
return [ $path, $old, $new ]
if defined $old;
}
elsif ( !is_ref($new) ) {
return !!1
return [ $path, $old, $new ]
if is_ref($old)
or $new ne $old;
}
elsif ( is_plain_arrayref($new) ) {
return !!1
return [ $path, $old, $new ]
if !is_plain_arrayref($old) || @$new != @$old;
push @queue, map [ $old->[$_], $new->[$_] ], 0 .. $#$new;
push @queue, map [ $old->[$_], $new->[$_], "$path/$_" ],
0 .. $#$new;
}
elsif ( is_plain_hashref($new) ) {
return !!1
if !is_plain_hashref($old) || keys %$new != keys %$old;
push @queue, map [ $old->{$_}, $new->{$_} ], keys %$new;
return [ $path, $old, $new ]
if !is_plain_hashref($old)
|| !$allow_extra && keys %$new != keys %$old;
push @queue, map [ $old->{$_}, $new->{$_}, "$path/$_" ],
keys %$new;
}
else {
die "can't compare $new type data";
die "can't compare $new type data at $path";
}
}
return !!0;
return undef;
}

1;
Expand Down

0 comments on commit 333322d

Please sign in to comment.