Front-end performance improvement: Implementing a Promise cache for similar GET requests

@pierre-gilles,

A quick question. Today, in the edit menu, we retrieve the list of devices/features x times — x being the list of boxes — when opening each dashboard?

If that’s the case, would it be useful to share the list of devices retrieved just when opening the editor? Or would that have no impact?

Yes indeed!

That could be interesting, but it’s not a simple problem

1 Like

Indeed, with all the chart tests there, when I have dashboards with many Chart boxes + devices, it starts to take a bit of time to display (2/3s). In itself nothing serious, but you can see that processing the device lists takes time.

I’ll investigate later to really know whether it’s the multiple get devices calls that take time or if it’s the processing behind creating the feature lists by removing the selected ones (I suspect the get device because it happens whether I have a selection or not).

But honestly it’s not bothersome in itself. It would just be smoother ^^

I see!

We could set up a Promise cache system to prevent 2 requests from being sent at the same time.

Ex: 2 widgets call the same API. The first widget sends the request and the second simply waits for the result of that same request.

This avoids having 2 calls in parallel for the same thing, but it also doesn’t create any cache issues because we’re only caching the execution (not the result)

1 Like

I can fully picture the logic, which should indeed work.
However, on the code side, I can’t picture it at all :stuck_out_tongue_winking_eye:

Shall I create a GitHub issue for our records? ^^

1 Like

Yes, you can create one!

1 Like

I made a PR that implements this behavior, both locally and via Gladys Plus :slight_smile:

The PR :

If you want to test the difference on Gladys Plus :

https://add-cache-for-pending-reques.gladys-plus.pages.dev

I’d be curious to see the difference on your side! On my end it’s already relatively fast so I don’t see much difference

1 Like

There’s no comparison!! A slight loading for the 1st box and the rest is instantaneous ^^

Do you want a comparison GIF?

You can post a small mp4 on the forum :slight_smile:

(as long as it’s sufficiently compressed)

Before / After, you can clearly see the scrollbar on the left that keeps growing ^^ :

visutempscharge2-ezgif.com-optimizevisu temps charge1

1 Like

Great, I’ll merge :slight_smile:

3 Likes

Fixed in Gladys Assistant 4.52.0: