Skip to content

Commit

Permalink
Do not bump OAI-PMH without reason
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Apr 22, 2024
1 parent 23fed18 commit b710d4e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
22 changes: 20 additions & 2 deletions lib/AmuseWikiFarm/Schema/Result/Site.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5546,9 +5546,20 @@ sub create_aggregation {
}
my $aggregation = $self->aggregations->find({ aggregation_uri => $rec{aggregation_uri} });
my @existing_uris;
my $bump_pmh = 1;
if ($aggregation) {
Dlog_debug { "Updating aggregation with $_" } \%rec;
$aggregation->update(\%rec);
foreach my $k (sort keys %rec) {
$aggregation->$k($rec{$k});
}
if ($aggregation->is_changed) {
Dlog_debug { "Aggregation was updated $_" } +{ $aggregation->get_dirty_columns };
$aggregation->update;
}
else {
log_debug { "No changes in the aggregation" };
$bump_pmh = 0;
}
@existing_uris = map { $_->uri } $aggregation->titles;
}
else {
Expand All @@ -5574,7 +5585,14 @@ sub create_aggregation {
}
}
Dlog_debug { "Aggregation changed $_" } +{ from => \@existing_uris, to => \@uris };
$aggregation->bump_oai_pmh_records;
if ($bump_pmh
or join('|', @existing_uris) ne join('|', @uris)) {
Dlog_info { "Bumping OAI PMH records for " . $aggregation->aggregation_uri . " aggregation $_" } \@uris;
$aggregation->bump_oai_pmh_records;
}
else {
log_info { "No OAI-PMH update for aggregation " . $aggregation->aggregation_uri };
}
$guard->commit;
$aggregation->discard_changes;
return $aggregation;
Expand Down
13 changes: 12 additions & 1 deletion t/aggregations.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN {
};

use Data::Dumper;
use Test::More tests => 203;
use Test::More tests => 204;
use AmuseWikiFarm::Schema;
use File::Spec::Functions qw/catfile catdir/;
use lib catdir(qw/t lib/);
Expand Down Expand Up @@ -505,6 +505,17 @@ $site->delete;
like $agg->aggregation_series->comment_html, qr{<em>valid</em>};
}

{
my $max = $site->oai_pmh_records->search(undef, { order_by => { -desc => 'datestamp' }, rows => 1 })->first;
diag $max->datestamp;
diag "Reimporting and checking if ts changed";
DumpFile($autoimport->child('aggregations.yml'), $site->serialize_aggregations);
sleep 2;
$site->process_autoimport_files;
my $newmax = $site->oai_pmh_records->search(undef, { order_by => { -desc => 'datestamp' }, rows => 1 })->first;
is $max->datestamp->epoch, $newmax->datestamp->epoch;
}

sub check_oai_pmh {
my ($s, $now, $expect_records, $msg) = @_;
sleep 1;
Expand Down

0 comments on commit b710d4e

Please sign in to comment.