[freeside-commits] branch FREESIDE_3_BRANCH updated. 47a277c86e3b7c298bf15ad4e803085b9ce2bb31
Ivan
ivan at 420.am
Tue Feb 25 16:23:22 PST 2014
The branch, FREESIDE_3_BRANCH has been updated
via 47a277c86e3b7c298bf15ad4e803085b9ce2bb31 (commit)
from bbafa11d873514973aa202ddccc3de9de2528eb3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 47a277c86e3b7c298bf15ad4e803085b9ce2bb31
Author: Ivan Kohler <ivan at freeside.biz>
Date: Tue Feb 25 16:23:20 2014 -0800
fix perf edge case with multiple large packages, on svc insert, RT#26097
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index 002df54..1dcd601 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -4,6 +4,7 @@ use strict;
use vars qw( @ISA $DEBUG $me $ignore_quantity $conf $ticket_system );
use Carp;
#use Scalar::Util qw( blessed );
+use List::Util qw( max );
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh str2time_sql );
use FS::cust_pkg;
@@ -364,15 +365,26 @@ sub check {
return "Unknown svcpart" unless $part_svc;
if ( $self->pkgnum && ! $ignore_quantity ) {
- my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
- return "Unknown pkgnum" unless $cust_pkg;
- ($part_svc) = grep { $_->svcpart == $self->svcpart } $cust_pkg->part_svc;
- return "No svcpart ". $self->svcpart.
- " services in pkgpart ". $cust_pkg->pkgpart
- unless $part_svc || $ignore_quantity;
- return "Already ". $part_svc->get('num_cust_svc'). " ". $part_svc->svc.
+
+ #slightly inefficient since ->pkg_svc will also look it up, but fixing
+ # a much larger perf problem and have bigger fish to fry
+ my $cust_pkg = $self->cust_pkg;
+
+ my $pkg_svc = $self->pkg_svc
+ or return "No svcpart ". $self->svcpart.
+ " services in pkgpart ". $cust_pkg->pkgpart;
+
+ my $num_cust_svc = $cust_pkg->num_cust_svc( $self->svcpart );
+
+ #false laziness w/cust_pkg->part_svc
+ my $num_avail = max( 0, ($cust_pkg->quantity || 1) * $pkg_svc->quantity
+ - $num_cust_svc
+ );
+
+ return "Already $num_cust_svc ". $pkg_svc->part_svc->svc.
" services for pkgnum ". $self->pkgnum
- if !$ignore_quantity && $part_svc->get('num_avail') <= 0 ;
+ if $num_avail <= 0;
+
}
$self->SUPER::check;
-----------------------------------------------------------------------
Summary of changes:
FS/FS/cust_svc.pm | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)
More information about the freeside-commits
mailing list