From 0a8ac1f354bb604a0e0988d3d2e43fe8a7f0386d Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 16 Jun 2014 14:10:20 +0200 Subject: [PATCH] SL::DB::{Chart,Part}: Verwendung von $::request->cache() --- SL/DB/Chart.pm | 2 +- SL/DB/Part.pm | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/SL/DB/Chart.pm b/SL/DB/Chart.pm index db8a3b945..7c50b43d3 100644 --- a/SL/DB/Chart.pm +++ b/SL/DB/Chart.pm @@ -17,7 +17,7 @@ sub get_active_taxkey { my ($self, $date) = @_; $date ||= DateTime->today_local; - my $cache = $::request->{cache}{chart}{$date}; + my $cache = $::request->cache("get_active_taxkey")->{$date} //= {}; if ($cache->{$self->id}) { return $cache->{$self->id}; } diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index ae2612b9d..a0f9c1034 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -144,9 +144,7 @@ sub get_taxkey { my $date = $params{date} || DateTime->today_local; my $is_sales = !!$params{is_sales}; my $taxzone = $params{ defined($params{taxzone}) ? 'taxzone' : 'taxzone_id' } * 1; - - $self->{__partpriv_taxkey_information} ||= { }; - my $tk_info = $self->{__partpriv_taxkey_information}; + my $tk_info = $::request->cache('get_taxkey'); $tk_info->{$taxzone} ||= { }; $tk_info->{$taxzone}->{$is_sales} ||= { }; @@ -167,8 +165,8 @@ sub get_chart { my $type = (any { $_ eq $params{type} } qw(income expense inventory)) ? $params{type} : croak("Invalid 'type' parameter '$params{type}'"); my $taxzone = $params{ defined($params{taxzone}) ? 'taxzone' : 'taxzone_id' } * 1; - $self->{__partpriv_get_chart_id} ||= { }; - my $charts = $self->{__partpriv_get_chart_id}; + my $charts = $::request->cache('get_chart_id/by_taxzones'); + my $all_charts = $::request->cache('get_chart_id/by_id'); $charts->{$taxzone} ||= { }; @@ -177,7 +175,11 @@ sub get_chart { my $chart_id = ($type eq 'inventory') ? ($self->inventory_accno_id ? $bugru->inventory_accno_id : undef) : $bugru->call_sub("${type}_accno_id_${taxzone}"); - $charts->{$taxzone}->{$type} = $chart_id ? SL::DB::Chart->new(id => $chart_id)->load : undef; + if ($chart_id) { + my $chart = $all_charts->{$chart_id} // SL::DB::Chart->new(id => $chart_id)->load; + $all_charts->{$chart_id} = $chart; + $charts->{$taxzone}->{$type} = $chart; + } } return $charts->{$taxzone}->{$type}; -- 2.20.1