From 067aa1c5f731bc9eac40ff53e6c3be2e58ef1c0f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 15 May 2020 11:46:07 +0000 Subject: [PATCH] Bug 25278: add clear_search_fields_cache method Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- Koha/SearchEngine/Elasticsearch.pm | 24 +++++++++++++++---- admin/searchengine/elasticsearch/mappings.pl | 6 +---- .../SearchEngine/Elasticsearch/QueryBuilder.t | 10 +------- .../Koha/SearchEngine/Elasticsearch/Reset.t | 6 +---- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 7afb9aab54..a43b864145 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -382,11 +382,7 @@ sub reset_elasticsearch_mappings { } } - my $cache = Koha::Caches->get_instance(); - $cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios'); - $cache->clear_from_cache('elasticsearch_search_fields_opac_biblios'); - $cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities'); - $cache->clear_from_cache('elasticsearch_search_fields_opac_authorities'); + $self->clear_search_fields_cache(); # FIXME return the mappings? } @@ -1287,6 +1283,24 @@ sub get_facetable_fields { return ( @faceted_fields, @not_faceted_fields ); } +=head2 clear_search_fields_cache + +Koha::SearchEngine::Elasticsearch->clear_search_fields_cache(); + +Clear cached values for ES search fields + +=cut + +sub clear_search_fields_cache { + + my $cache = Koha::Caches->get_instance(); + $cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios'); + $cache->clear_from_cache('elasticsearch_search_fields_opac_biblios'); + $cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities'); + $cache->clear_from_cache('elasticsearch_search_fields_opac_authorities'); + +} + 1; __END__ diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index 5212c2a5cb..57a9656f9c 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -165,11 +165,7 @@ if ( $op eq 'edit' ) { push @messages, { type => 'message', code => 'success_on_update' }; $schema->storage->txn_commit; - my $cache = Koha::Caches->get_instance(); - $cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios'); - $cache->clear_from_cache('elasticsearch_search_fields_opac_biblios'); - $cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities'); - $cache->clear_from_cache('elasticsearch_search_fields_opac_authorities'); + Koha::SearchEngine::Elasticsearch->clear_search_fields_cache(); $update_mappings->(); } diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index a3ff646bad..bf6d77d70e 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -101,14 +101,6 @@ $se->mock( 'get_elasticsearch_mappings', sub { return $all_mappings{$self->index}; }); -my $cache = Koha::Caches->get_instance(); -my $clear_search_fields_cache = sub { - $cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios'); - $cache->clear_from_cache('elasticsearch_search_fields_opac_biblios'); - $cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities'); - $cache->clear_from_cache('elasticsearch_search_fields_opac_authorities'); -}; - subtest 'build_authorities_query_compat() tests' => sub { plan tests => 57; @@ -635,7 +627,7 @@ subtest 'build_query with weighted fields tests' => sub { $search_field->update({ weight => 25.0 }); $search_field = Koha::SearchFields->find({ name => 'subject' }); $search_field->update({ weight => 15.5 }); - $clear_search_fields_cache->(); + Koha::SearchEngine::Elasticsearch->clear_search_fields_cache(); my ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { weighted_fields => 1 }); diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t index 0c07a260d6..e57ee16596 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t @@ -72,8 +72,4 @@ is($title_sf->weight, '20.00', 'Title search field is weighted with 20'); $schema->storage->txn_rollback; -$cache = Koha::Caches->get_instance(); -$cache->clear_from_cache('elasticsearch_search_fields_staff_client_biblios'); -$cache->clear_from_cache('elasticsearch_search_fields_opac_biblios'); -$cache->clear_from_cache('elasticsearch_search_fields_staff_client_authorities'); -$cache->clear_from_cache('elasticsearch_search_fields_opac_authorities'); +Koha::SearchEngine::Elasticsearch->clear_search_fields_cache(); -- 2.39.5