From: Ivan Kohler Date: Wed, 10 Feb 2016 06:27:03 +0000 (-0800) Subject: optimize Reports->Customers->List Customers, RT#20173 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=f7329b766b496393064a4dd4df2515cbfbb00827 optimize Reports->Customers->List Customers, RT#20173 --- diff --git a/FS/FS/Maketext.pm b/FS/FS/Maketext.pm index c90e57303..b4a9b81c7 100644 --- a/FS/FS/Maketext.pm +++ b/FS/FS/Maketext.pm @@ -1,6 +1,6 @@ package FS::Maketext; - use base qw( Exporter ); + use FS::CurrentUser; use FS::Conf; use FS::L10N; @@ -10,6 +10,13 @@ our @EXPORT_OK = qw( mt emt js_mt ); our $lh; +our $locale; +#ask FS::UID to run this stuff for us later +FS::UID->install_callback( sub { + my $conf = new FS::Conf; + $locale = $conf->config('locale'); +}); + sub mt { return '' if $_[0] eq ''; $lh ||= lh(); @@ -32,8 +39,8 @@ sub js_mt { } sub lh { - my $locale = $FS::CurrentUser::CurrentUser->option('locale') - || FS::Conf->new->config('locale') + my $locale = $FS::CurrentUser::CurrentUser->locale + || $locale || 'en_US'; $locale =~ s/_/-/g; FS::L10N->get_handle($locale) || die "Unknown locale $locale"; diff --git a/FS/FS/Msgcat.pm b/FS/FS/Msgcat.pm index ce0fa78af..b6f36bf95 100644 --- a/FS/FS/Msgcat.pm +++ b/FS/FS/Msgcat.pm @@ -61,7 +61,7 @@ sub _gettext { return '' unless defined($msgcode) && length($msgcode) > 0; my $locale = (@_ && shift) - || $FS::CurrentUser::CurrentUser->option('locale') + || $FS::CurrentUser::CurrentUser->locale || $def_locale; return $cache{$locale}->{$msgcode} if exists $cache{$locale}->{$msgcode}; diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm index 77706b1db..3a12ef395 100644 --- a/FS/FS/access_user.pm +++ b/FS/FS/access_user.pm @@ -731,6 +731,17 @@ sub change_password_fields { FS::Auth->auth_class->change_password_fields( @_ ); } +=item locale + +=cut + +sub locale { + my $self = shift; + return $self->{_locale} if exists($self->{_locale}); +warn "access_user->locale called\n"; + $self->{_locale} = $self->option('locale'); +} + =back =head1 BUGS diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 97bce4537..3adbc06e8 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -4,7 +4,9 @@ use base qw( FS::part_pkg::API ); use strict; -use vars qw( %plans $DEBUG $setup_hack $skip_pkg_svc_hack ); +use vars qw( %plans $DEBUG $setup_hack $skip_pkg_svc_hack + $cache_enabled %cache_link %cache_pkg_svc + ); use Carp qw(carp cluck confess); use Scalar::Util qw( blessed ); use DateTime; @@ -33,9 +35,14 @@ use FS::part_pkg_currency; use FS::part_svc_link; $DEBUG = 0; + $setup_hack = 0; $skip_pkg_svc_hack = 0; +$cache_enabled = 0; +%cache_link = (); +%cache_pkg_svc = (); + =head1 NAME FS::part_pkg - Object methods for part_pkg objects @@ -1104,6 +1111,9 @@ definition. sub pkg_svc { my $self = shift; + return @{ $cache_pkg_svc{$self->pkgpart} } + if $cache_enabled && $cache_pkg_svc{$self->pkgpart}; + # #sort { $b->primary cmp $a->primary } # grep { $_->quantity } # qsearch( 'pkg_svc', { 'pkgpart' => $self->pkgpart } ); @@ -1128,7 +1138,11 @@ sub pkg_svc { } } - values(%pkg_svc); + my @pkg_svc = values(%pkg_svc); + + $cache_pkg_svc{$self->pkgpart} = \@pkg_svc if $cache_enabled; + + @pkg_svc; } @@ -1406,8 +1420,7 @@ sub option { return $self->hashref->{"_$opt"}; } - cluck "$self -> option: searching for $opt" - if $DEBUG; + cluck "$self -> option: searching for $opt" if $DEBUG; my $part_pkg_option = qsearchs('part_pkg_option', { pkgpart => $self->pkgpart, @@ -1541,14 +1554,25 @@ sub supp_part_pkg_link { sub _part_pkg_link { my( $self, $type ) = @_; - qsearch({ table => 'part_pkg_link', - hashref => { 'src_pkgpart' => $self->pkgpart, - 'link_type' => $type, - #protection against infinite recursive links - 'dst_pkgpart' => { op=>'!=', value=> $self->pkgpart }, - }, - order_by => "ORDER BY hidden", - }); + + return @{ $cache_link{$type}->{$self->pkgpart} } + if $cache_enabled && $cache_link{$type}->{$self->pkgpart}; + + cluck $type.'_part_pkg_link called' if $DEBUG; + + my @ppl = + qsearch({ table => 'part_pkg_link', + hashref => { src_pkgpart => $self->pkgpart, + link_type => $type, + #protection against infinite recursive links + dst_pkgpart => { op=>'!=', value=> $self->pkgpart }, + }, + order_by => "ORDER BY hidden", + }); + + $cache_link{$type}->{$self->pkgpart} = \@ppl if $cache_enabled; + + return @ppl; } sub self_and_bill_linked { diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index 9f4963d55..aabc0b98b 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -119,6 +119,7 @@ % foreach my $cust_pkg ( @{$all_pkgs{$custnum}} ) { % my %cust_svc_by_svcpart; % my $rows = 0; +% local($FS::part_pkg::cache_enabled) = 1; #for $cust_pkg->part_svc % foreach my $part_svc ( % $cust_pkg->part_svc( summarize_size=>$large_pkg_size ) % ) {