Bug 41440: Add caching to language_get_description and get_rfc4646_from_iso639

This should have no visible effect, just internal caching

To test:
1 - Do a search, check the language facets
2 - Apply patch, restart all
3 - Do a search, check the language facets
4 - No change
5 - Sign off

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 694765da2f)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
This commit is contained in:
Nick Clemens 2025-12-12 14:29:39 +00:00 committed by Jacob O'Mara
parent 8493af0e04
commit c26cef4481
No known key found for this signature in database
1 changed files with 13 additions and 1 deletions

View File

@ -480,6 +480,12 @@ Missing POD for language_get_description.
sub language_get_description {
my ( $script, $lang, $type ) = @_;
my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
my $cache_key = "Language_descriptions:$script:$lang:$type";
my $cached = $memory_cache->get_from_cache($cache_key);
return $cached if $cached;
my $dbh = C4::Context->dbh;
my $desc;
my $sth = $dbh->prepare("SELECT description FROM language_descriptions WHERE subtag=? AND lang=? AND type=?");
@ -496,6 +502,7 @@ sub language_get_description {
$desc = $descriptions->{'description'};
}
}
$memory_cache->set_in_cache( $cache_key, $desc );
return $desc;
}
@ -797,9 +804,14 @@ sub getlanguage {
sub get_rfc4646_from_iso639 {
my $iso_code = shift;
my $iso_code = shift;
my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
my $cache_key = "RFC4646ByISO639:$iso_code";
my $cached = $memory_cache->get_from_cache($cache_key);
return $cached if $cached;
my $rfc_subtag =
Koha::Database->new()->schema->resultset('LanguageRfc4646ToIso639')->find( { iso639_2_code => $iso_code } );
$memory_cache->set_in_cache( $cache_key, $rfc_subtag );
if ($rfc_subtag) {
return $rfc_subtag->rfc4646_subtag;
} else {