Optimizing "Do a search for"

Hi,

I have multiple elements on a page (15-20 items) and all of them get their data by using “do a search for”. I imagine this means that it has to pull from the database for each item individually, therefore it pulls 15-20 times.

Would this be considered an unoptimized setup?

And if so, what can I do to optimize it? Is there anyway to do a single “do a search for” on page load? I suppose I could a single one and store all of the data in custom states, but is that efficient?

Thank you,
Mikhaeel

Hi there, @mikhaeel… yes, what you are doing is almost certainly an unoptimized setup. In order to understand how to address it, I think the main question is what are you displaying in those 15-20 elements? Do the elements show data that is associated with a single record in your database or are they all unrelated? If you can share more details about what you are doing, I’m sure someone will be able to help you figure out a better (more optimized) path forward.

Best…
Mike

Hi @mikeloc,

Thanks for your reply.

Yes, all these elements are showing data associated with a single record. The vast majority of them are text and a few images. Do you think doing a single “do a search for” and storing all the required data in custom states is a more efficient option?

Thanks,
Mikhaeel

Well, anything is more efficient than doing a search in every text element. :slight_smile:

All kidding aside, you don’t have to “store all the required data” anywhere in order to access a record’s data. You simply need to set something on the page to the record itself, and then the elements will be able to access the record’s data. For example, you could put all of the elements in a group, and you could have the data source of the group be a search for the record. You could also set the page’s type of content to the record’s data type, and you could send the record to the page as part of navigating to the page.

Anyway, you have options, but understanding the general concept is the important part here.

You’ll have to structure it in a way that it will not load the data on each item on page load. Pushing it to custom states is too much work, especially if you rely on the data being updated realtime.

When you have a vertical scrolling repeating group, this is exactly what’s happening. As long as there are not advanced filters in play, the results should be quite fast.

Just make sure you set the data for the search only when the page is fully loaded :wink:

Haha, yes I understand.

Is there any way to set the page data source as “do a search for”? I noticed I can only do that by sending the data from another page?

Thanks for the reply!

So you’re saying that pulling each one individually is actually not really inefficient?

You can set a custom state’s value to the record on page load, and you could have the data source of a group on the page set to the custom state’s value.

Oh, and I’m not sure what you and nocodventure are talking about there, but let me be clear (in case I wasn’t already)… you ABSOLUTELY POSITIVELY DO NOT want to do a search in every text element on your page! :slight_smile:

1 Like

Gotcha Mike! Thanks for the input :+1:

If it’s a single text record, then like @mikeloc said you should not do a search for every individual element.

From what I understood though is that you have a single record with data inside of it. So for example Vehicle A will display the brand name, brand year, color etc.

In this case you’ll do a search for Vehicle #item 1 > Then display the items based on the data you set on the group.

See the demo below;

Yep, makes sense. Thank you!