Loading Delay Bug (+Bugfix) for .toStatic() on Lookups

This sub-forum is for discussing all topics related to AppGini Helper JavaScript Library, provided by bizzworxx as a third-party AppGini plugin.
Post Reply
User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1817
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Loading Delay Bug (+Bugfix) for .toStatic() on Lookups

Post by jsetzer » 2023-08-28 09:13

:idea: TL;DR

If you have >5 seconds loading-delay when using AppGiniHelper.DV.getField("FIELDNAME").toStatic() on a lookup-field, try passing null as 1st and true as 2nd parameter:

Code: Select all

AppGiniHelper.DV.getField("FIELDNAME").toStatic(null, true);
---

Problem

Recently I was wondering about loading delay in DV. Duration-measurement from page-load till AppGini hided the "loading"-indicator was >5 seconds:
chrome_ryScp5prlJ.png
chrome_ryScp5prlJ.png (1.28 KiB) Viewed 2301 times
Loaded in 5.159s :o

---

After narrowing down my javascript code I figured out the delay came from just one line of code:

Code: Select all

// file: hooks/TABLENAME-dv.js
//...
AppGiniHelper.DV.getField("type_id").toStatic();
//...
:idea: Info

That toStatic()-function converts a lookup field...
chrome_cFWLRviXRp.png
chrome_cFWLRviXRp.png (3.6 KiB) Viewed 2301 times

...into a (readonly) display field:
chrome_vHIWaLuMlK.png
chrome_vHIWaLuMlK.png (1.65 KiB) Viewed 2301 times
(Note: I'm using this a lot for example for denying changes after initial insert or for keeping the relation to the parent record)

The function automatically waits for lazy-loaded lookup-controls. This means usually we don't have to care for the field-type but just call the function and let the helper do the rest.

Obviously, this leads to delays on page-load, so I did some research.

Reason

There is one problem: Before hiding the "loading"-indicator (and showing the detail view), AppGini waits for certain HTML elements. In this case it waits for the lookup-control, identified by classname .select2-container. If we change our lookup to a static-control, this .select2-container never appears. This means AppGini waits until timeout after 5 seconds. And this brings the delay.

Solution

In these cases we can simulate existence of such a control and therefore let AppGini find a (hidden) dummy-element instead of waiting for timeout.

Fortunately, I've alread prepared the code for handling such issues. The only thing you have to do is pass true as 2nd parameter like this:

Code: Select all

AppGiniHelper.DV.getField("FIELDNAME").toStatic(null, true);
That small change reduced loading time from >5s to less than a second:
Loaded in 0.263s :)

Summary

What I have learned today: when using .toStatic() on a lookup field, pass true as 2nd parameter.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply