[freeside-commits] branch FREESIDE_3_BRANCH updated. 2087a0f972b1ef1cb918d2c2316577e533ffd3f1
Mark Wells
mark at 420.am
Thu Apr 24 13:05:28 PDT 2014
The branch, FREESIDE_3_BRANCH has been updated
via 2087a0f972b1ef1cb918d2c2316577e533ffd3f1 (commit)
from f36d4080bd950107273af70073549dc7684743db (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 2087a0f972b1ef1cb918d2c2316577e533ffd3f1
Author: Mark Wells <mark at freeside.biz>
Date: Thu Apr 24 11:59:57 2014 -0700
avoid excess memory usage in cust_main location upgrade, #28841
diff --git a/FS/FS/Cursor.pm b/FS/FS/Cursor.pm
index f3bc1e2..f59d8cb 100644
--- a/FS/FS/Cursor.pm
+++ b/FS/FS/Cursor.pm
@@ -56,7 +56,7 @@ sub new {
my $dbh = dbh;
my $sth = $dbh->prepare($statement)
or die $dbh->errstr;
- my $bind = 0;
+ my $bind = 1;
foreach my $value ( @{ $q->{value} } ) {
my $bind_type = shift @{ $q->{bind_type} };
$sth->bind_param($bind++, $value, $bind_type );
@@ -101,6 +101,12 @@ sub refill {
scalar @$result;
}
+sub DESTROY {
+ my $self = shift;
+ my $statement = "CLOSE ".$self->{id};
+ dbh->do($statement);
+}
+
=back
=head1 TO DO
diff --git a/FS/FS/cust_main/Location.pm b/FS/FS/cust_main/Location.pm
index 52fe313..62a7423 100644
--- a/FS/FS/cust_main/Location.pm
+++ b/FS/FS/cust_main/Location.pm
@@ -4,6 +4,7 @@ use strict;
use vars qw( $DEBUG $me @location_fields );
use FS::Record qw(qsearch qsearchs);
use FS::UID qw(dbh);
+use FS::Cursor;
use FS::cust_location;
use Carp qw(carp);
@@ -135,6 +136,7 @@ sub _upgrade_data {
|| new FS::contact_class { classname => 'Service'};
if ( !$service_contact_class->classnum ) {
+ warn "Creating service contact class.\n";
$error = $service_contact_class->insert;
die "error creating contact class for Service: $error" if $error;
}
@@ -156,7 +158,9 @@ sub _upgrade_data {
}
}
- foreach my $cust_main (qsearch('cust_main', { bill_locationnum => '' })) {
+ warn "Migrating customer locations.\n";
+ my $search = FS::Cursor->new('cust_main', { bill_locationnum => '' });
+ while (my $cust_main = $search->fetch) {
# Step 1: extract billing and service addresses into cust_location
my $custnum = $cust_main->custnum;
my $bill_location = FS::cust_location->new(
@@ -281,9 +285,9 @@ sub _upgrade_data {
if $error;
# Step 4: set packages at the "default service location" to ship_location
- foreach my $cust_pkg (
- qsearch('cust_pkg', { custnum => $custnum, locationnum => '' })
- ) {
+ my $pkg_search =
+ FS::Cursor->new('cust_pkg', { custnum => $custnum, locationnum => '' });
+ while (my $cust_pkg = $pkg_search->fetch) {
# not a location change
$cust_pkg->set('locationnum', $cust_main->ship_locationnum);
$error = $cust_pkg->replace;
@@ -291,7 +295,7 @@ sub _upgrade_data {
if $error;
}
- } #foreach $cust_main
+ } #while (my $cust_main...)
# repair an error in earlier upgrades
if (!FS::upgrade_journal->is_done('cust_location_censustract_repair')
-----------------------------------------------------------------------
Summary of changes:
FS/FS/Cursor.pm | 8 +++++++-
FS/FS/cust_main/Location.pm | 14 +++++++++-----
2 files changed, 16 insertions(+), 6 deletions(-)
More information about the freeside-commits
mailing list