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

(-)a/C4/Koha.pm (-12 / +27 lines)
Lines 25-33 use strict; Link Here
25
25
26
use C4::Context;
26
use C4::Context;
27
use C4::Branch qw(GetBranchesCount);
27
use C4::Branch qw(GetBranchesCount);
28
use Koha::Cache;
28
use Koha::DateUtils qw(dt_from_string);
29
use Koha::DateUtils qw(dt_from_string);
29
use Memoize;
30
use Memoize::Expire;
31
use DateTime::Format::MySQL;
30
use DateTime::Format::MySQL;
32
use autouse 'Data::Dumper' => qw(Dumper);
31
use autouse 'Data::Dumper' => qw(Dumper);
33
use DBI qw(:sql_types);
32
use DBI qw(:sql_types);
Lines 78-88 BEGIN { Link Here
78
@EXPORT_OK = qw( GetDailyQuote );
77
@EXPORT_OK = qw( GetDailyQuote );
79
}
78
}
80
79
81
# expensive functions
82
tie my %memoize_cache => 'Memoize::Expire',
83
  LIFETIME            => 10;
84
memoize('GetAuthorisedValues', SCALAR_HASH => [HASH => \%memoize_cache]);
85
86
=head1 NAME
80
=head1 NAME
87
81
88
C4::Koha - Perl Module containing convenience functions for Koha scripts
82
C4::Koha - Perl Module containing convenience functions for Koha scripts
Lines 1027-1039 This function returns all authorised values from the'authorised_value' table in Link Here
1027
1021
1028
C<$category> returns authorised values for just one category (optional).
1022
C<$category> returns authorised values for just one category (optional).
1029
1023
1024
C<$selected> adds a "selected => 1" entry to the hash if the
1025
authorised_value matches it. B<NOTE:> this feature should be considered
1026
deprecated as it may be removed in the future.
1027
1030
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist.
1028
C<$opac> If set to a true value, displays OPAC descriptions rather than normal ones when they exist.
1031
1029
1032
=cut
1030
=cut
1033
1031
1034
sub GetAuthorisedValues {
1032
sub GetAuthorisedValues {
1035
    my ( $category, $selected, $opac ) = @_;
1033
    my ( $category, $selected, $opac ) = @_;
1036
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1034
1035
    # TODO: the "selected" feature should be replaced by a utility function
1036
    # somewhere else, it doesn't belong in here. For starters it makes
1037
    # caching much more complicated. Or just let the UI logic handle it, it's
1038
    # what it's for.
1039
1040
    # Is this cached already?
1041
    $opac = $opac ? 1 : 0; # normalise to be safe
1042
    my $selected_key = defined($selected) ? $selected : '';
1043
    my $cache_key = "AuthorisedValues-$category-$selected_key-$opac";
1044
    my $cache     = Koha::Cache->get_instance();
1045
    my $result    = $cache->get_from_cache($cache_key);
1046
warn "fetched $result from cache";
1047
    return $result if $result;
1048
1049
    my $branch_limit =
1050
      C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
1037
    my @results;
1051
    my @results;
1038
    my $dbh      = C4::Context->dbh;
1052
    my $dbh      = C4::Context->dbh;
1039
    my $query = qq{
1053
    my $query = qq{
Lines 1079-1084 sub GetAuthorisedValues { Link Here
1079
        push @results, $data;
1093
        push @results, $data;
1080
    }
1094
    }
1081
    $sth->finish;
1095
    $sth->finish;
1096
1097
    # We can't cache for long because of that "selected" thing which
1098
    # makes it impossible to clear the cache without iterating through every
1099
    # value, which sucks. This'll cover this request, and not a whole lot more.
1100
    $cache->set_in_cache( $cache_key, \@results, { deepcopy => 1, expiry => 5 } );
1082
    return \@results;
1101
    return \@results;
1083
}
1102
}
1084
1103
Lines 1257-1265 Create a new authorised value. Link Here
1257
sub AddAuthorisedValue {
1276
sub AddAuthorisedValue {
1258
    my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_;
1277
    my ($category, $authorised_value, $lib, $lib_opac, $imageurl) = @_;
1259
1278
1260
    # clear the memoize cache
1261
    flush_cache('AddAuthorisedValue');
1262
1263
    my $dbh = C4::Context->dbh;
1279
    my $dbh = C4::Context->dbh;
1264
    my $query = qq{
1280
    my $query = qq{
1265
        INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl)
1281
        INSERT INTO authorised_values (category, authorised_value, lib, lib_opac, imageurl)
1266
- 

Return to bug 9967