[freeside-commits] branch master updated. 662be3ece2ef8c7f05fcbfaa699d80a6a73ca110

Ivan ivan at 420.am
Tue Feb 25 16:23:20 PST 2014


The branch, master has been updated
       via  662be3ece2ef8c7f05fcbfaa699d80a6a73ca110 (commit)
       via  439d00a59c67a7d9d53b5d89c14ab332be16e38b (commit)
       via  0e0b58d3384aeaf24634319ceeb10a51ef3c26eb (commit)
      from  cf69a36faa57cdb544948c905059cf1e1ac73e07 (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 662be3ece2ef8c7f05fcbfaa699d80a6a73ca110
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Feb 25 16:23:19 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 7bf41ee..be5a9eb 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -5,6 +5,7 @@ use strict;
 use vars qw( $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::part_pkg;
@@ -363,15 +364,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;

commit 439d00a59c67a7d9d53b5d89c14ab332be16e38b
Merge: 0e0b58d cf69a36
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Feb 25 16:23:14 2014 -0800

    Merge branch 'master' of git.freeside.biz:/home/git/freeside


commit 0e0b58d3384aeaf24634319ceeb10a51ef3c26eb
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Tue Feb 25 01:56:38 2014 -0800

    remove debug

diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm
index 862cceb..4f41219 100644
--- a/FS/FS/ClientAPI/MyAccount.pm
+++ b/FS/FS/ClientAPI/MyAccount.pm
@@ -555,8 +555,8 @@ sub customer_info_short {
                       1, ##nobalance
                     );
 
-warn    $return{first}  = $cust_main->first;
-warn    $return{'last'} = $cust_main->get('last');
+    $return{first}  = $cust_main->first;
+    $return{'last'} = $cust_main->get('last');
     $return{name}   = $cust_main->first. ' '. $cust_main->get('last');
 
     $return{payby} = $cust_main->payby;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/ClientAPI/MyAccount.pm |    4 ++--
 FS/FS/cust_svc.pm            |   28 ++++++++++++++++++++--------
 2 files changed, 22 insertions(+), 10 deletions(-)




More information about the freeside-commits mailing list