diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-08-09 15:19:32 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-08-09 15:19:32 -0700 |
commit | 96bfe632aeb28c7596bdfd5a7a98f0464f5ad6a5 (patch) | |
tree | 0fff7090118d8ada3eca08c11a5de7e25ff8f7e0 /FS | |
parent | 7de7c267ca9e04b1f057307ac03325c6d37228f2 (diff) |
optimizations for large package lists, RT#28526
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_pkg.pm | 36 | ||||
-rw-r--r-- | FS/FS/location_Mixin.pm | 17 | ||||
-rw-r--r-- | FS/FS/part_pkg.pm | 10 |
3 files changed, 52 insertions, 11 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index 17505ddfc..75bbe1304 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -2757,7 +2757,7 @@ sub set_cust_pkg_detail { =item cust_event -Returns the new-style customer billing events (see L<FS::cust_event>) for this invoice. +Returns the customer billing events (see L<FS::cust_event>) for this invoice. =cut @@ -2774,19 +2774,41 @@ sub cust_event { =item num_cust_event -Returns the number of new-style customer billing events (see L<FS::cust_event>) for this invoice. +Returns the number of customer billing events (see L<FS::cust_event>) for this package. =cut #false laziness w/cust_bill.pm sub num_cust_event { my $self = shift; - my $sql = - "SELECT COUNT(*) FROM cust_event JOIN part_event USING ( eventpart ) ". - " WHERE tablenum = ? AND eventtable = 'cust_pkg'"; + my $sql = "SELECT COUNT(*) ". $self->_from_cust_event_where; + $self->_prep_ex($sql, $self->pkgnum)->fetchrow_arrayref->[0]; +} + +=item exists_cust_event + +Returns true if there are customer billing events (see L<FS::cust_event>) for this package. More efficient than using num_cust_event. + +=cut + +sub exists_cust_event { + my $self = shift; + my $sql = "SELECT 1 ". $self->_from_cust_event_where. " LIMIT 1"; + my $row = $self->_prep_ex($sql, $self->pkgnum)->fetchrow_arrayref; + $row ? $row->[0] : ''; +} + +sub _from_cust_event_where { + #my $self = shift; + " FROM cust_event JOIN part_event USING ( eventpart ) ". + " WHERE tablenum = ? AND eventtable = 'cust_pkg' "; +} + +sub _prep_ex { + my( $self, $sql, @args ) = @_; my $sth = dbh->prepare($sql) or die dbh->errstr. " preparing $sql"; - $sth->execute($self->pkgnum) or die $sth->errstr. " executing $sql"; - $sth->fetchrow_arrayref->[0]; + $sth->execute(@args) or die $sth->errstr. " executing $sql"; + $sth; } =item cust_svc [ SVCPART ] (old, deprecated usage) diff --git a/FS/FS/location_Mixin.pm b/FS/FS/location_Mixin.pm index d32b4a37c..b010374a9 100644 --- a/FS/FS/location_Mixin.pm +++ b/FS/FS/location_Mixin.pm @@ -11,9 +11,20 @@ Returns the location object, if any (see L<FS::cust_location>). =cut sub cust_location { - my $self = shift; + my( $self, %opt ) = @_; + return '' unless $self->locationnum; - qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } ); + + return $opt{_cache}->{$self->locationnum} + if $opt{_cache} && $opt{_cache}->{$self->locationnum}; + + my $cust_location = + qsearchs( 'cust_location', { 'locationnum' => $self->locationnum } ); + + $opt{_cache}->{$self->locationnum} = $cust_location + if $opt{_cache}; + + $cust_location; } =item cust_location_or_main @@ -25,7 +36,7 @@ L<FS::cust_location>), otherwise returns the customer (see L<FS::cust_main>). sub cust_location_or_main { my $self = shift; - $self->cust_location || $self->cust_main; + $self->cust_location(@_) || $self->cust_main; } =item location_label [ OPTION => VALUE ... ] diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index f90e3eec5..1682b6761 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -29,7 +29,7 @@ use FS::part_pkg_discount; use FS::part_pkg_usage; use FS::part_pkg_vendor; -$DEBUG = 0; +$DEBUG = 1; $setup_hack = 0; $skip_pkg_svc_hack = 0; @@ -1248,6 +1248,12 @@ will be suppressed. sub option { my( $self, $opt, $ornull ) = @_; + + #cache: was pulled up in the original part_pkg query + if ( $opt =~ /^(setup|recur)_fee$/ && defined($self->hashref->{"_$opt"}) ) { + return $self->hashref->{"_$opt"}; + } + cluck "$self -> option: searching for $opt" if $DEBUG; my $part_pkg_option = @@ -1256,12 +1262,14 @@ sub option { optionname => $opt, } ); return $part_pkg_option->optionvalue if $part_pkg_option; + my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); } split("\n", $self->get('plandata') ); return $plandata{$opt} if exists $plandata{$opt}; cluck "WARNING: (pkgpart ". $self->pkgpart. ") Package def option $opt ". "not found in options or plandata!\n" unless $ornull; + ''; } |