summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2009-04-22 20:24:58 +0000
committerivan <ivan>2009-04-22 20:24:58 +0000
commit5a136db0ab9c700c8ab4b2093b240448cda0ee37 (patch)
tree830d07f81d302caf87bca9e85f951f81c67ab45e
parent5d730c723b94d385eb9fb1c87d8e576af668a1e4 (diff)
hopefully better performance running the big query once and then fetching results with a cursor, rather than running it multiple times with an OFFSET and LIMIT, RT#4412
-rw-r--r--FS/FS/Cron/bill.pm35
1 files changed, 16 insertions, 19 deletions
diff --git a/FS/FS/Cron/bill.pm b/FS/FS/Cron/bill.pm
index 7f79b4dd5..3222d1509 100644
--- a/FS/FS/Cron/bill.pm
+++ b/FS/FS/Cron/bill.pm
@@ -91,33 +91,30 @@ END
push @search, "( $where_pkg OR $where_bill_event )";
- my $prev_custnum = 0;
- while ( 1 ) {
-
- ###
- # get a list of custnums
- ###
-
- warn "searching for customers:\n".
- join("\n", @search).
- "custnum > $prev_custnum\n"
- if $opt{'v'} || $opt{'l'};
+ ###
+ # get a list of custnums
+ ###
- my $sth = dbh->prepare(
- "SELECT custnum FROM cust_main".
- " WHERE ". join(' AND ', @search).
- " AND custnum > $prev_custnum ".
- " ORDER BY custnum LIMIT 1000 "
- ) or die dbh->errstr;
+ warn "searching for customers:\n". join("\n", @search). "\n"
+ if $opt{'v'} || $opt{'l'};
+ dbh->do(
+ "DECLARE cron_bill_cursor CURSOR WITH HOLD FOR ". #no WITH HOLD for mysql?
+ " SELECT custnum FROM cust_main ".
+ " WHERE ". join(' AND ', @search).
+ " ORDER BY custnum " #LIMIT 1000 "
+ ) or die dbh->errstr;
+
+ while ( 1 ) {
+
+ my $sth = dbh->prepare('FETCH 1000 FROM cron_bill_cursor'); #mysql?
+
$sth->execute or die $sth->errstr;
my @custnums = map { $_->[0] } @{ $sth->fetchall_arrayref };
last unless scalar(@custnums);
- $prev_custnum = $custnums[-1];
-
###
# for each custnum, queue or make one customer object and bill
# (one at a time, to reduce memory footprint with large #s of customers)