inline init() to avoid cstore startup race condition
authorBill Erickson <berickxx@gmail.com>
Wed, 18 Sep 2019 19:57:13 +0000 (15:57 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 15 Oct 2019 18:09:56 +0000 (14:09 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Search.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm

index f025bb7..b1d34d9 100644 (file)
@@ -37,7 +37,6 @@ sub initialize {
 sub child_init {
     OpenILS::Application::Search::Z3950->child_init;
     OpenILS::Application::Search::Browse->child_init;
-    OpenILS::Application::Search::Elastic->child_init;
 }
     
 
index 178b3d8..0a16511 100644 (file)
@@ -36,11 +36,16 @@ my $bib_fields;
 my $hidden_copy_statuses;
 my $hidden_copy_locations;
 my $avail_copy_statuses;
-our $enabled = {};
 
-sub child_init {
+# NOTE calling cstore functions in child_init is dicey because child_init
+# may be run before cstore is ready for requests.  Use a local init() instead.
+my $init_done = 0;
+sub init {
     my $class = shift;
 
+    return if $init_done;
+    $init_done = 1;
+
     my $e = new_editor();
 
     $bib_fields = $e->retrieve_all_elastic_bib_field;
@@ -158,6 +163,8 @@ sub bib_search {
     my ($self, $client, $query, $options) = @_;
     $options ||= {};
 
+    init();
+
     my $staff = ($self->api_name =~ /staff/);
 
     return {count => 0, ids => []} unless $query && $query->{query};