Bugzilla – Attachment 103014 Details for
Bug 23137
Add a command line tool to reset elasticsearch mappings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23137: Move cache flushing to the method
Bug-23137-Move-cache-flushing-to-the-method.patch (text/plain), 4.72 KB, created by
Jonathan Druart
on 2020-04-15 14:38:32 UTC
(
hide
)
Description:
Bug 23137: Move cache flushing to the method
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-04-15 14:38:32 UTC
Size:
4.72 KB
patch
obsolete
>From 9e7a2d009a638f920a90539949054929dcc9f18d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 15 Apr 2020 16:38:16 +0200 >Subject: [PATCH] Bug 23137: Move cache flushing to the method > >--- > Koha/SearchEngine/Elasticsearch.pm | 7 +++++++ > admin/searchengine/elasticsearch/mappings.pl | 13 +++++-------- > misc/search_tools/rebuild_elasticsearch.pl | 4 ---- > .../Koha/SearchEngine/Elasticsearch/Reset.t | 11 ++++++++++- > 4 files changed, 22 insertions(+), 13 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 19fa2a47fa..6616671325 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -26,6 +26,7 @@ use Koha::Exceptions::Config; > use Koha::Exceptions::Elasticsearch; > use Koha::SearchFields; > use Koha::SearchMarcMaps; >+use Koha::Caches; > use C4::Heading; > > use Carp; >@@ -382,6 +383,12 @@ sub reset_elasticsearch_mappings { > } > } > } >+ >+ my $cache = Koha::Caches->get_instance(); >+ $cache->clear_from_cache('elasticsearch_search_fields_staff_client'); >+ $cache->clear_from_cache('elasticsearch_search_fields_opac'); >+ >+ # FIXME return the mappings? > } > > # This overrides the accessor provided by Class::Accessor so that if >diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl >index 0ed7aa2522..d5f39fbcaa 100755 >--- a/admin/searchengine/elasticsearch/mappings.pl >+++ b/admin/searchengine/elasticsearch/mappings.pl >@@ -69,12 +69,6 @@ my $update_mappings = sub { > } > }; > >-my $cache = Koha::Caches->get_instance(); >-my $clear_cache = sub { >- $cache->clear_from_cache('elasticsearch_search_fields_staff_client'); >- $cache->clear_from_cache('elasticsearch_search_fields_opac'); >-}; >- > if ( $op eq 'edit' ) { > > $schema->storage->txn_begin; >@@ -161,13 +155,16 @@ if ( $op eq 'edit' ) { > } else { > push @messages, { type => 'message', code => 'success_on_update' }; > $schema->storage->txn_commit; >- $clear_cache->(); >+ >+ my $cache = Koha::Caches->get_instance(); >+ $cache->clear_from_cache('elasticsearch_search_fields_staff_client'); >+ $cache->clear_from_cache('elasticsearch_search_fields_opac'); >+ > $update_mappings->(); > } > } > elsif( $op eq 'reset_confirmed' ) { > Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; >- $clear_cache->(); > push @messages, { type => 'message', code => 'success_on_reset' }; > } > elsif( $op eq 'reset_confirm' ) { >diff --git a/misc/search_tools/rebuild_elasticsearch.pl b/misc/search_tools/rebuild_elasticsearch.pl >index 78b7a41639..d19f69f3d2 100755 >--- a/misc/search_tools/rebuild_elasticsearch.pl >+++ b/misc/search_tools/rebuild_elasticsearch.pl >@@ -112,7 +112,6 @@ use Koha::MetadataRecord::Authority; > use Koha::BiblioUtils; > use Koha::SearchEngine::Elasticsearch; > use Koha::SearchEngine::Elasticsearch::Indexer; >-use Koha::Caches; > use MARC::Field; > use MARC::Record; > use Modern::Perl; >@@ -156,9 +155,6 @@ _sanity_check(); > > if ($reset){ > Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; >- my $cache = Koha::Caches->get_instance(); >- $cache->clear_from_cache('elasticsearch_search_fields_staff_client'); >- $cache->clear_from_cache('elasticsearch_search_fields_opac'); > $delete = 1; > } > >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t >index 7222bc0e0d..dc8e29a4d8 100644 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t >@@ -17,10 +17,11 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > use Test::MockModule; > > use Koha::Database; >+use Koha::Caches; > > my $indexes = { > 'authorities' => { >@@ -54,8 +55,12 @@ Koha::SearchFields->search->delete; > Koha::SearchMarcMaps->search->delete; > $schema->resultset('SearchMarcToField')->search->delete; > >+ > Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; > >+my $cache = Koha::Caches->get_instance(); >+is( $cache->get_from_cache('elasticsearch_search_fields_staff_client'), undef, 'Cache has been flushed by reset_elasticsearch_mappings' ); >+ > my $search_fields = Koha::SearchFields->search({}); > is($search_fields->count, 2, 'There is 2 search fields after reset'); > >@@ -66,3 +71,7 @@ my $title_sf = Koha::SearchFields->search({ name => 'title' })->next; > 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'); >+$cache->clear_from_cache('elasticsearch_search_fields_opac'); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23137
:
101051
|
101052
|
102354
|
102355
|
102918
|
103014
|
103640
|
103647
|
103648
|
103649
|
103650