Page 1 of 1

Superfast omit of many records

PostPosted: Wed Feb 20, 2013 9:40 am
by Peter de Groot
Something I want to share,

One of our users was complaining that the printing of some selected records takes very long to complete, user needs to print 4 out of 256 records...

The code we use to do this is:

Code: Select all
var v_fs, v_form;

v_fs   = forms.exp_poLinesHeatnrList.foundset.duplicateFoundSet();

for (var i = v_fs.getSize(); i > 0; i--) {
   var v_rec = v_fs.getRecord(i);
   if (!v_rec.checkbox) { //checkbox not checked
      v_fs.omitRecord(i);
   }
}

Doing it this way it takes about 21 seconds to omit the not selected record from v_fs :oops: ,

but when doing it like this:
Code: Select all
var v_fs, v_form, v_arrSelected;

v_fs          = forms.exp_poLinesHeatnrList.foundset.duplicateFoundSet();
v_fs.multiSelect   = true;
v_arrSelected   = new Array();

for (var i = 1 ; i <= v_fs.getSize(); i++) {
   var v_rec = v_fs.getRecord(i);
   if (v_rec.checkbox != 1) {//checkbox not checked
      v_arrSelected.push(i);
   }
}
v_fs.setSelectedIndexes(v_arrSelected);
v_fs.omitRecord();


The omit is done nearly instantaneously :shock:

regards,

Peter

Re: Superfast omit of many records

PostPosted: Wed Feb 20, 2013 12:25 pm
by jasantana
Good one. Thanks for sharing.

Re: Superfast omit of many records

PostPosted: Thu Feb 21, 2013 10:18 am
by jcarlos
Thank you for sharing too :-)

Re: Superfast omit of many records

PostPosted: Thu Feb 21, 2013 5:52 pm
by Manolo_Etec
Thanks for sharing too. :D

Re: Superfast omit of many records

PostPosted: Thu Feb 21, 2013 9:27 pm
by Harjo
be aware, that if you omit more than 200 records this way, Servoy will (auto) create a temp table first, because of performance.
So be sure that you have create table rights on that server, or else you'll get a database permission error

it would be nice if we could tell Servoy, to point to a specific server, for that, because in our case we have one database where we only have read access to.

Re: Superfast omit of many records

PostPosted: Fri Feb 22, 2013 1:54 pm
by pbakker
It would be nice if we could tell Servoy, to point to a specific server

The temp table needs to be in the same database as the database against which the SQL is fired, so the temp table can be joint in the SQL statement.

If the temp table would reside in a different database, there would be no point of having the temp table in the first place

As for the technique: Maybe I'm missing the point, but I think what would be even faster would be looping over the original foundset to find all your "selected" records, get the PK Value(s) of each record and insert it into JSDataSet, then create an new foundset and load it with the JSDataSet: This will require no database interaction at all.

Paul