[freeside-commits] freeside/FS/FS/Cron bill.pm,1.2.2.10,1.2.2.11

Ivan,,, ivan at wavetail.420.am
Wed Apr 22 13:25:00 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS/Cron
In directory wavetail.420.am:/tmp/cvs-serv25864

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	bill.pm 
Log Message:
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

Index: bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Cron/bill.pm,v
retrieving revision 1.2.2.10
retrieving revision 1.2.2.11
diff -u -d -r1.2.2.10 -r1.2.2.11
--- bill.pm	22 Apr 2009 06:52:14 -0000	1.2.2.10
+++ bill.pm	22 Apr 2009 20:24:58 -0000	1.2.2.11
@@ -91,33 +91,30 @@
   
   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)



More information about the freeside-commits mailing list