Hi Lesouef,
The foundsetUpdater does what the name implies...it updates the foundset (and therefor the database).
Can you tell us what the actual change to the data is? I mean are you using information of the same record to change some columns? Or perhaps some related data from this record? Or is it more of a general update using non-related data?
To understand this would help us to see what the best option would be because there are several options:
- this loop
- foundsetUpdater
- loop combined with foundsetUpdater
- pure SQL update
Also your code can be optimized a little. You declare div, $rec and $result in the loop over and over again. Declaring them once is enough.
Also the following code can be simplified.
- Code: Select all
var div = ($i+1)/1000 ; // pitch
if (div== Math.floor(div)) {
into
- Code: Select all
if ( $i%1000 == 0 ) {
Also your for loop is zero based but the foundset is 1 based (starts with 1) so you keep adding 1 to $i when you addressing the record. Why not just changing the for loop code instead:
- Code: Select all
for (var $i = 1 ; $i <= foundset.getSize() ; $i++) {
So your code would be looking like this:
- Code: Select all
function import_srl_post_process() {
var $rec,
$result;
databaseManager.setAutoSave(false);
databaseManager.startTransaction();
for (var $i = 1 ; $i <= foundset.getSize() ; $i++) {
$rec = foundset.getRecord($i);
if ($rec.semarq != null) {
.......stuff here..........
} else {
........other stuff here.........
}
if ($i%1000 == 0) {
$result = databaseManager.commitTransaction();
databaseManager.startTransaction();
application.output("updated " + $i +" recs. result="+$result);
}
}
$result = databaseManager.commitTransaction();
application.output("updated " + $stop +" recs. result=" + $result );
databaseManager.setAutoSave(true);
}