Storing value pairs

Hello

Looking for some advice on how to handle some repeatedly used value pairs on a page. On my page, I want to show some graphs along with text and I find myself running the same database searches for the same information over and over again. I am retrieving several items along with their count. For example
Item 1 has count of 5
Item 2 has count of 10
Item 3 has count of 1

I use this to display some graphs and do some calculations.

Is there a way to just do the search 1 time and then store it somewhere that can be referenced? Would this even be of benefit over just doing multiple searches? Basically I am looking to create value pairs such as {item, count}.

I may be overthinking this and doing multiple database searches is just fine, but I am currently doing the same searches 4 times, so I would think there is more optimal method.

Thanks in advance
Andy

If you’re doing the same search on the page 4 times, then it will only actually be done once (not 4 times)… so there’s no need to worry about that.

Is there a way to just do the search 1 time and then store it somewhere that can be referenced?

That’s exactly what happens automatically by default (assuming it actually is the same search, or a sub-set of it. If it’s actually a different search then the new search will obviously be made).

You can check all of that for yourself in the network tab of your browser developer tools if you want to see for yourself what searches are being made, and when.

(I may actually be misunderstanding your question. as I’m not sure what you mean by “retrieving several items along with their count” if they are all the same type of item?.. unless it’s not the same search you’re doing)

Hi Adam

Thanks for the reply. I am not sure if the search would only happen once. The searches occur for different elements on the page. For example, I have 2 charts, a repeating group, and another text element.

You can imagine an invoicing app. I would have line items, where I will reference each item and their count. I also have a pie chart, which shows the same info. So I am pretty sure that searches are executed for each element

It’s not about what elements you’re calling the search in…

You can have 100 elements on the page, all calling the same search (even at different times)…

The search (and download of the data) will still only be done once.

But, if they are different searches (i.e. with different constraints) then they will be made independently.

In which case it might be slightly faster to load ALL the data you need onto the page first, and then just filter it in your elements (which will happen automatically anyway once all the data has been loaded onto the page)…

But the difference is probably tiny.

In any case, you need whatever data you need on the page… so you have to search for it one way or another.

Bubble is clever enough that it won’t do the same search more than once if the data is already on the page, so it’s usually not something you need to worry about (at least not from a performance perspective).

That’s good to know. Yes, they are all using the exact same constraints.
Sounds like I’ll just keep in doing that then and not worry too much about it.

Thanks for the feedback

1 Like