Skip to content

Commit

Permalink
fix: fix cache on countries list (#9721)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarel authored Feb 5, 2024
1 parent a283cd8 commit 867c794
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/ProductOpener/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 867c794

Please sign in to comment.