|
Lines 93-99
sub find_by_koha_field {
Link Here
|
| 93 |
distinct => 1, |
93 |
distinct => 1, |
| 94 |
} |
94 |
} |
| 95 |
); |
95 |
); |
| 96 |
return $av->count ? $av->next : undef; |
96 |
return $av->next; |
| 97 |
} |
97 |
} |
| 98 |
|
98 |
|
| 99 |
sub get_description_by_koha_field { |
99 |
sub get_description_by_koha_field { |
|
Lines 106-119
sub get_description_by_koha_field {
Link Here
|
| 106 |
|
106 |
|
| 107 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
107 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
| 108 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value"; |
108 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield:$authorised_value"; |
| 109 |
my $cached = $memory_cache->get_from_cache($cache_key); |
109 |
my $description = $memory_cache->get_from_cache($cache_key); |
| 110 |
return $cached if $cached; |
110 |
|
| 111 |
|
111 |
unless (defined $description) { |
| 112 |
my $av = $self->find_by_koha_field($params); |
112 |
my $av = $self->find_by_koha_field($params); |
| 113 |
return {} unless defined $av; |
113 |
$description = defined $av ? { lib => $av->lib, opac_description => $av->opac_description } : {}; |
| 114 |
my $descriptions = { lib => $av->lib, opac_description => $av->opac_description }; |
114 |
$memory_cache->set_in_cache( $cache_key, $description ); |
| 115 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
115 |
} |
| 116 |
return $descriptions; |
116 |
return $description; |
| 117 |
} |
117 |
} |
| 118 |
|
118 |
|
| 119 |
sub get_descriptions_by_koha_field { |
119 |
sub get_descriptions_by_koha_field { |
|
Lines 123-141
sub get_descriptions_by_koha_field {
Link Here
|
| 123 |
|
123 |
|
| 124 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
124 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
| 125 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield"; |
125 |
my $cache_key = "AV_descriptions:$frameworkcode:$kohafield"; |
| 126 |
my $cached = $memory_cache->get_from_cache($cache_key); |
126 |
my $descriptions = $memory_cache->get_from_cache($cache_key); |
| 127 |
return @$cached if $cached; |
127 |
|
|
|
128 |
unless (defined $descriptions) { |
| 129 |
my @avs = $self->search_by_koha_field($params)->as_list; |
| 130 |
$descriptions = [ |
| 131 |
map { |
| 132 |
{ |
| 133 |
authorised_value => $_->authorised_value, |
| 134 |
lib => $_->lib, |
| 135 |
opac_description => $_->opac_description |
| 136 |
} |
| 137 |
} @avs |
| 138 |
]; |
| 139 |
$memory_cache->set_in_cache( $cache_key, $descriptions ); |
| 140 |
} |
| 141 |
return @{$descriptions}; |
| 142 |
} |
| 128 |
|
143 |
|
| 129 |
my @avs = $self->search_by_koha_field($params)->as_list; |
144 |
sub get_description_by_category_and_authorised_value { |
| 130 |
my @descriptions = map { |
145 |
my ( $self, $params ) = @_; |
| 131 |
{ |
146 |
return unless defined $params->{category} && defined $params->{authorised_value}; |
| 132 |
authorised_value => $_->authorised_value, |
147 |
|
| 133 |
lib => $_->lib, |
148 |
my $category = $params->{category}; |
| 134 |
opac_description => $_->opac_description |
149 |
my $value = $params->{authorised_value}; |
| 135 |
} |
150 |
|
| 136 |
} @avs; |
151 |
my $memory_cache = Koha::Cache::Memory::Lite->get_instance; |
| 137 |
$memory_cache->set_in_cache( $cache_key, \@descriptions ); |
152 |
my $cache_key = "AV_description_by_category_and_authorised_value:$category:$value"; |
| 138 |
return @descriptions; |
153 |
my $description = $memory_cache->get_from_cache($cache_key); |
|
|
154 |
|
| 155 |
unless (defined $description) { |
| 156 |
my $av = $self->search( |
| 157 |
{ |
| 158 |
category => $category, |
| 159 |
authorised_value => $value |
| 160 |
} |
| 161 |
)->next; |
| 162 |
$description = defined $av ? { |
| 163 |
lib => $av->lib, |
| 164 |
opac_description => $av->opac_description |
| 165 |
} : {}; |
| 166 |
$memory_cache->set_in_cache( $cache_key, $description ); |
| 167 |
} |
| 168 |
|
| 169 |
return $description; |
| 139 |
} |
170 |
} |
| 140 |
|
171 |
|
| 141 |
sub categories { |
172 |
sub categories { |