View | Details | Raw Unified | Return to bug 31856
Collapse All | Expand All

(-)a/C4/Biblio.pm (-21 / +11 lines)
Lines 114-119 use Koha::SearchEngine; Link Here
114
use Koha::SearchEngine::Indexer;
114
use Koha::SearchEngine::Indexer;
115
use Koha::Libraries;
115
use Koha::Libraries;
116
use Koha::Util::MARC;
116
use Koha::Util::MARC;
117
use Koha::AuthorisedValues;
117
118
118
=head1 NAME
119
=head1 NAME
119
120
Lines 1444-1471 sub GetAuthorisedValueDesc { Link Here
1444
    }
1445
    }
1445
1446
1446
    my $dbh = C4::Context->dbh;
1447
    my $dbh = C4::Context->dbh;
1447
    if ( $category ne "" ) {
1448
    if ( $category ) {
1448
        $cache_key = "AV_descriptions:" . $category;
1449
        my $description = Koha::AuthorisedValues->get_description_by_category_and_authorised_value(
1449
        my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
1450
            {
1450
        if ( !$av_descriptions ) {
1451
                category => $category,
1451
            $av_descriptions = {
1452
                authorised_value => $value
1452
                map {
1453
            }
1453
                    $_->authorised_value =>
1454
        );
1454
                      { lib => $_->lib, lib_opac => $_->lib_opac }
1455
        return $opac ?
1455
                } Koha::AuthorisedValues->search(
1456
            $description->{'opac_description'} : $description->{'lib'};
1456
                    { category => $category },
1457
                    {
1458
                        columns => [ 'authorised_value', 'lib_opac', 'lib' ]
1459
                    }
1460
                )->as_list
1461
            };
1462
            $cache->set_in_cache($cache_key, $av_descriptions);
1463
        }
1464
        return ( $opac && $av_descriptions->{$value}->{'lib_opac'} )
1465
          ? $av_descriptions->{$value}->{'lib_opac'}
1466
          : $av_descriptions->{$value}->{'lib'};
1467
    } else {
1457
    } else {
1468
        return $value;    # if nothing is found return the original value
1458
        return $value; # if nothing is found return the original value
1469
    }
1459
    }
1470
}
1460
}
1471
1461
(-)a/Koha/AuthorisedValue.pm (-8 / +6 lines)
Lines 52-69 sub store { Link Here
52
    }
52
    }
53
    else {
53
    else {
54
        my %updated_columns = $self->_result->get_dirty_columns;
54
        my %updated_columns = $self->_result->get_dirty_columns;
55
55
        $flush = exists $updated_columns{lib}
56
        if (   exists $updated_columns{lib}
56
            or exists $updated_columns{lib_opac};
57
            or exists $updated_columns{lib_opac} )
58
        {
59
            $flush = 1;
60
        }
61
    }
57
    }
62
58
63
    $self = $self->SUPER::store;
59
    $self = $self->SUPER::store;
64
60
65
    if ($flush) {
61
    if ($flush) {
66
        my $key = "AV_descriptions:".$self->category;
62
        my $category = $self->category;
63
        my $key = "AV_descriptions:$category";
67
        $cache->clear_from_cache($key);
64
        $cache->clear_from_cache($key);
68
    }
65
    }
69
66
Lines 78-84 AuthorisedValue specific C<delete> to clear relevant caches on delete. Link Here
78
75
79
sub delete {
76
sub delete {
80
    my $self = shift @_;
77
    my $self = shift @_;
81
    my $key = "AV_descriptions:".$self->category;
78
    my $category = $self->category;
79
    my $key = "AV_descriptions:$category";
82
    $cache->clear_from_cache($key);
80
    $cache->clear_from_cache($key);
83
    $self->SUPER::delete(@_);
81
    $self->SUPER::delete(@_);
84
}
82
}
(-)a/Koha/AuthorisedValues.pm (-19 / +19 lines)
Lines 143-172 sub get_descriptions_by_koha_field { Link Here
143
143
144
sub get_description_by_category_and_authorised_value {
144
sub get_description_by_category_and_authorised_value {
145
    my ( $self, $params ) = @_;
145
    my ( $self, $params ) = @_;
146
    return unless defined $params->{category} && defined $params->{authorised_value};
146
    return unless defined $params->{category} and defined $params->{authorised_value};
147
147
148
    my $category = $params->{category};
148
    my $category = $params->{category};
149
    my $value = $params->{authorised_value};
149
    my $value = $params->{authorised_value};
150
150
151
    my $memory_cache = Koha::Cache::Memory::Lite->get_instance;
151
    my $cache = Koha::Caches->get_instance();
152
    my $cache_key = "AV_description_by_category_and_authorised_value:$category:$value";
152
    my $cache_key = "AV_descriptions:$category";
153
    my $description = $memory_cache->get_from_cache($cache_key);
153
    my $descriptions = $cache->get_from_cache($cache_key, { unsafe => 1 });
154
154
155
    unless (defined $description) {
155
    unless (defined $descriptions) {
156
        my $av = $self->search(
156
        $descriptions = {
157
            {
157
            map {
158
                category => $category,
158
                $_->authorised_value => {
159
                authorised_value => $value
159
                    lib => $_->lib,
160
            }
160
                    opac_description => $_->opac_description
161
        )->next;
161
                }
162
        $description = defined $av ? {
162
            } $self->search(
163
            lib => $av->lib,
163
                {
164
            opac_description => $av->opac_description
164
                    category => $category
165
        } : {};
165
                }
166
        $memory_cache->set_in_cache( $cache_key, $description );
166
            )->as_list
167
        };
168
        $cache->set_in_cache($cache_key, $descriptions);
167
    }
169
    }
168
170
    return defined $descriptions->{$value} ? $descriptions->{$value} : {};
169
    return $description;
170
}
171
}
171
172
172
sub categories {
173
sub categories {
173
- 

Return to bug 31856