From 867c794229d516b9ca30b4cd7869e217c746f7b2 Mon Sep 17 00:00:00 2001 From: Alex Garel Date: Mon, 5 Feb 2024 15:51:22 +0100 Subject: [PATCH] fix: fix cache on countries list (#9721) --- lib/ProductOpener/Web.pm | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/ProductOpener/Web.pm b/lib/ProductOpener/Web.pm index 62ae9d150e926..8bafdfc825791 100644 --- a/lib/ProductOpener/Web.pm +++ b/lib/ProductOpener/Web.pm @@ -351,25 +351,30 @@ A reference to a list of hashes with every country code and their label in the $ sub get_countries_options_list ($target_lc, $exclude_world = 1) { # if already computed send it back + my @countries_list = (); if (defined $countries_options_lists{$target_lc}) { - return $countries_options_lists{$target_lc}; + @countries_list = @{$countries_options_lists{$target_lc}}; } - # compute countries list - my @countries_list = (); - my @tags_list = get_all_taxonomy_entries("countries"); - foreach my $tag (@tags_list) { - next if $exclude_world and ($tag eq 'en:world'); - my $country = display_taxonomy_tag($target_lc, "countries", $tag); - # remove eventual language prefix - my $country_no_code = $country; - $country_no_code =~ s/^\w\w://; - # Adding to the list the modified string - push @countries_list, {value => $tag, label => $country_no_code, prefixed => $country}; + else { + # compute countries list + my @tags_list = get_all_taxonomy_entries("countries"); + foreach my $tag (@tags_list) { + my $country = display_taxonomy_tag($target_lc, "countries", $tag); + # remove eventual language prefix + my $country_no_code = $country; + $country_no_code =~ s/^\w\w://; + # Adding to the list the modified string + push @countries_list, {value => $tag, label => $country_no_code, prefixed => $country}; + } + # sort by name + @countries_list = sort {$unicode_collate->cmp($a->{label}, $b->{label})} @countries_list; + # cache + $countries_options_lists{$target_lc} = \@countries_list; + } + if ($exclude_world) { + # remove world + @countries_list = grep {$_->{value} ne "world"} @countries_list; } - # sort by name - @countries_list = sort {$unicode_collate->cmp($a->{label}, $b->{label})} @countries_list; - # cache - $countries_options_lists{$target_lc} = \@countries_list; return \@countries_list; }