Delayed loading of records

Hi,

We use a framework that has a master form and below that there are related forms
in a tabpanel.
( for instance customer is master and employees and products are related forms)

The related forms are placed using forms.form.elements.tab.addTab(…).

Now the question :

When the related forms are placed i can see ( in the performnace data ) that a query
is performed for each tabform.

This can be an expensive operation if there are several related forms.
And it is not of much use to the user, as he can only see one tab at a time !

However, when i scroll trough the records of the master form, I can see that
only the form on the active tab is queried, not the forms in the non-active tabs.

I would like to place the related forms, but not load records for the forms in tabs
that are not active, only for the active tab.

Hope this makes sense.

In the 4gl i used there was an option to not do a query on a form until
it is shown. (delayed …)

Regards,

Hans Nieuwenhuis:
I would like to place the related forms, but not load records for the forms in tabs
that are not active, only for the active tab.

Have a look at databaseManager.setCreateEmptyFormFoundsets().

how do you use addTab()?

like this?

addTab(x,y, relation,z) ?

do it like this

addTab(x,y, “relationname”,z)

so relation as a string name.

I use variables so :

forms[_tab_form][_tab_relation]

forms[_tab_form].elements.tabs.addTab( forms[_form_at_tab], '', globals.nav.program[globals.nav.program[_program].tab*.program_name].description, null, null, null, null, forms[_tab_form][_tab_relation])*
*```*
*should i put the name of the relation in the variable _tab_relation in " " ??*
*B.t.w. why would using "relation" behave different ??*
*Regards,*
*Hans*

Hi Nicola,

Thanks for your answer, but it does only seem to work with the first (initial) form of the solution.

Also in the help is says :

Turns off the default foundset record loading for the initial form; must be called as part of the On open method selected in the Solutions Settings dialog; similar to calling foundset.clearFoundset as a form onLoad event.

Regards,

Hans

From my understanding that should affect all newly created foundsets, if you set it to not load records when you show a form with a new foundset that foundset will be empty instead of containing all the table records. I’ve never used it tough.

Hans Nieuwenhuis:
I use variables so :
forms[_tab_form][_tab_relation]
B.t.w. why would using “relation” behave different ??

so _tab_relation is a string, the relation name? just put that one in directly instead of getting the relation

It is very simple why just the string will behave different. when you do

forms.x.relation

you touch the relation so it has to and will be loaded so that you can do stuff on it like asking or the size or getting a record and its data

but if you just give the add tab a string then you dont touch the relation so it will not be loaded and internally it stays a string until you select the tab and the tab looks up the relation based on that string.

Hi Johan,

So i changed

forms[_tab_form].elements.tabs.addTab( forms[_form_at_tab], '', globals.nav.program[globals.nav.program[_program].tab*.program_name].description, null, null, null, null, forms[_tab_form][_tab_relation])*
*```*
*to*
*```*
<em>forms[_tab_form].elements.tabs.addTab( forms[_form_at_tab], '', globals.nav.program[globals.nav.program[_program].tab*.program_name].description, null, null, null, null, _tab_relation)*</em>
_*```*_
_*I assume that is what You meant ??*_
_*This seems to do the trick, I'l do some more testing.*_
_*Thanks very much Johan, Servoy still has features I am not aware of (yet).*_
_*Regards,*_
_*Hans*_

Hi Johan,

Is my code correct now ?

The number of queries fired is a lot less now, BUT there are still some
queries that should not be fired.

I guess I can create a case for this but first I want to be sure that my code is correct.

Regards,

yes that code is fine
As long as you just point to the relation by name and not the object itself it shouldnt be loaded.

Hi Johan,

Just created a very simple form : master with empty tab panel and 3 related child forms.

The code I use to place the forms on the tabs is :

suc = forms.par1s.elements.tabs.addTab( forms.ch1, 'ch1',  'ch1', null, null,  null,  null, 'par1s_to_ch1s')

suc = forms.par1s.elements.tabs.addTab( forms.ch2, 'ch2',  'ch2', null, null,  null,  null, 'par1s_to_ch2s')

suc = forms.par1s.elements.tabs.addTab( forms.ch3, 'ch3',  'ch3', null, null,  null,  null, 'par1s_to_ch3s')

when i start the solution the parent form is shown with now tabs. A buttonclick executes the above code and the 3 tabs are there.

Only the tab for ch1 is active, i do not switch to the other tabs.

When I then look at the performance data in Servoy Server Page I see that there where queries done for all
3 childforms.

This should not be the case right ??

Regards,

The output in Servoy Server Page is :

00:00:016 1 00:00:016 Find select * from ( select ID from CH2S order by ID asc ) where rownum <= ?
00:00:000 1 00:00:000 Find select * from ( select ID from CH1S order by ID asc ) where rownum <= ?
00:00:000 1 00:00:000 Find select * from ( select ID from CH3S order by ID asc ) where rownum <= ?
00:00:000 1 00:00:000 Find select * from ( select ID, PAR1_ID, NAAM from CH1S where ID in (?, ?, ?, ?, ?, ?) ) where rownum <= ?
00:00:000 3 00:00:000 Relation select * from ( select ID, PAR1_ID, NAAM from CH1S where PAR1_ID = ? order by ID asc ) where rownum <= ?
00:00:000 1 00:00:000 Find select * from ( select ID, PAR1_ID, NAAM from CH2S where ID in (?, ?, ?, ?, ?, ?) ) where rownum <= ?
00:00:000 1 00:00:000 Find select * from ( select ID, PAR1_ID, NAAM from CH3S where ID in (?, ?, ?, ?, ?, ?) ) where rownum <= ?

so 6 finds and 1 relation, does that mean that when the childforms are loaded, they do a find by themself ??

Regards,

the first 3 looks like pk selects

the 4th is a fill of row data of 1 of the above pk selects

then 1 relation query

and again 3 row data queries for the other 2

so there is only 1 relation query there. But 3 are existing foundsets that do a load or refresh
So they where already loaded.

Oke, but all queries are executed when the above code is executed.

Maybe the 3 finds are done when the forms in the tabs are loaded ??

They are the result of the 3 addTabs, i cleared the performance data, just before pressing the button.

Regards,

Hans

Hi,

I now added “databaseManager.setCreateEmptyFormFoundsets()” to the onOpen method of the solution.

Now the only query (so not 7) that is done when i push the button is :

00:00:000 3 00:00:000 Relation select * from ( select ID, PAR1_ID, NAAM from CH1S where PAR1_ID = ? order by ID asc ) where rownum <= ?

This is what Nicola already suggested.

Thanks guys, i guess this is the way the cut down on non-needed queries : only use relation name and use setCreateEmptyFormFoundsets.

Now you have to use loadRecords or loadAllRecords on the parent form, the related forms are populated automatically.

Have a great weekend !!

Regards,

Hans

ahh the forms you do touch when you set them as tabpanels do load first there normal query… (so that are the 2 queries per form)

I could change that that you also can use addTab with “formname” instead of a form…
then that is also lazy.

Would be a geat feature !! to be able to choose wether the foundset is initially loaded or not.

Regards,

Hans

you can already choose that by that setting that setting you now have.

if you can add a tab by relationname and formname instead of relation itself and the form itself it is just a bit more lazy

Yes,

But then you also can choose a different behaviour per form.

The setting I use now, is used for all forms.

For instance i would like that behaviour for forms on a tabpanel,
not for the master form.

Regards,

Hans

i think you can also already do that

in the onload of the forms that you place in the tab you do this:

function onload()
{
foundset.clear();
}

if you do that then that form will also not load data.