Skip to content

Commit

Permalink
Improve the collection update for OAI-PMH
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Nov 20, 2023
1 parent 313f933 commit db25b5a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
28 changes: 21 additions & 7 deletions lib/AmuseWikiFarm/Schema/Result/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,14 @@ sub update_from_params {
my $site = $self->site;
my @locales = $site->supported_locales;
my $guard = $self->result_source->schema->txn_scope_guard;
# collect existing ids
my @title_ids = @{ $self->title_ids };
my $oai_pmh_set = $site->oai_pmh_sets->find_or_create({
set_spec => $self->oai_pmh_set_spec,
set_name => $self->canonical_title,
},
{ key => 'set_spec_site_id_unique' });
# collect existing records. We will need to bump them.
my @oai_pmh_record_ids = map { $_->oai_pmh_record_id } $oai_pmh_set->oai_pmh_record_sets->all;

LANG:
foreach my $lang (@locales) {
my $title = $params->{'title_' . $lang};
Expand Down Expand Up @@ -377,12 +383,20 @@ sub update_from_params {
$self->set_titles(\@titles);
$self->set_categories(\@cats);
}
# add the new ones and bump the records
push @title_ids, @{ $self->title_ids };
Dlog_debug { "Updating ids $_ in OAI-PMH" } \@title_ids;
if (@title_ids) {
$site->oai_pmh_records->by_title_id(\@title_ids)->bump_datestamp;
# we need to change the linkage between the record and the set and
# bumps the new ones.
my $tree = $site->node_title_tree;
my $self_node_id = $self->node_id;
my ($tree_spec) = grep { $_->{node_id} == $self_node_id } @{ $tree->{nodes} || []};
Dlog_debug { "Initial list of PMH records is $_" } \@oai_pmh_record_ids;
if ($tree_spec) {
my @new_oai_pmh_records = $site->oai_pmh_records->by_title_id($tree_spec->{title_ids})->landing_pages_only->all;
# this should clear the existing one and relink
$oai_pmh_set->set_oai_pmh_records(\@new_oai_pmh_records);
push @oai_pmh_record_ids, map { $_->oai_pmh_record_id } @new_oai_pmh_records;
}
Dlog_debug { "Final list of PMH records is $_" } \@oai_pmh_record_ids;
$site->oai_pmh_records->by_id(\@oai_pmh_record_ids)->bump_datestamp if @oai_pmh_record_ids;
$guard->commit;
}

Expand Down
13 changes: 13 additions & 0 deletions lib/AmuseWikiFarm/Schema/ResultSet/OaiPmhRecord.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,17 @@ sub by_title_id {
$self->search({ "$me.title_id" => { -in => $ids } });
}

sub by_id {
my ($self, $ids) = @_;
my $me = $self->current_source_alias;
$self->search({ "$me.oai_pmh_record_id" => { -in => $ids } });
}

sub landing_pages_only {
my ($self, $ids) = @_;
my $me = $self->current_source_alias;
# a dot in the path means that's a file format
$self->search({ "$me.identifier" => { -not_like => '%.%' } });
}

1;

0 comments on commit db25b5a

Please sign in to comment.