Items until - order of operation when intersect involved

Hi gang.

If you create a Repeating Group with a data source that uses “intersects with” and you want to limit the total number of records returned/displayed, where do you place “items until #” to ensure the full query and intersect happens before it’s truncated?

Example:
Search 1 returns 500 things
Search 2 returns 300 things
Intersect gives me the 250 unique things common to both searches
I want to display the first 10 of those 250 things.

":items until " seems to get tacked on to the preceding Do a Search, so I’m assuming it’s applying itself to Search 2 in my above example. Is there a way to essentially put parentheses around the [Search 1 intersect with Search 2] so that the 250 things , in my example, are what gets truncated to a list of 10?

Hopefully that made sense. Thanks!!

Using a parenthesis approach would be a huge improvement in Bubble’s data source fields. For now, I have found that setting a custom state to the value of one action (intersecting two lists) and then calling that state in the data source (custom state’s value :items until #10) is the best approach to be sure your “equations” are executed with the intended result.

1 Like

@williamtisdale great suggestion, thanks for the pro tip!

1 Like

@williamtisdale - quick follow-up: the reason for my wanting to limit the display to 10 things was largely performance concerns. Am I shooting myself in the foot with a custom state because the entire 250 has to get loaded into the state up front, whereas if do the intersect inside the Repeating Group, perhaps there’s some Bubble magic that will only load a handful of records at a time and grab the next as users scroll? Or is the expense of identifying the entire sorted list of 250 going to happen on page load any way you slice it?

I have other future efforts in mind where limiting to X items will be needed for screen real estate reasons, so this is still a super helpful tip. But if performance is the primary driver, I’m just wondering how well this scales if you’re dealing with hundreds or thousands of records in Search A and Search B. Thanks!

Hi, some info…

  • For a scrolling RG, Bubble will only load what’s needed to fill the slots on the screen, plus a few more in anticipation of the user scrolling. So you shouldn’t need an “items until” unless you want your user to have to hit a “show more” button or if you want to do a “next page” sort of thing.
  • My guess is that “:items until” will apply to the whole search if you put it at the end of the expression, since expressions are read left to right. But you’d need to run a test to see.
  • I did some experimentation with intersecting 2 server-side searches. The results were troubling: Bubble downloaded the ENTIRE results of each search, then finds the intersects client side (on your browser). What this means is if you have a lot of data (in the thousands), be prepared for really long waits and potential browser crashes. Here’s my post on that: Move complex search to backend - Need help / Database - Bubble Forum
  • If you use an advanced filter to do the intersect, at least Bubble will only download what’s needed to fill the RG. So for example, if your RG has space for 20 records, and in order to find 20 results Bubble needs to download 200 records and run them through the advanced filter client side, then 200 records are what is being downloaded. It’s still not that scalable (OK for hundreds of records, but not for thousands), but it’s better than Bubble downloading the ENTIRE results of both searches and then doing the intersects in the browser.

My recommendation is to become familiar with the network tab in google dev tools – you can use it to see exactly what Bubble is downloading to the page under various search approaches. But the unfortunate news is that most searches that don’t fit in the standard “search for box” get kicked to the client side, and that won’t work for an app that has a lot of records.

2 Likes

Do you have the parenthesis feature enabled?..

In which case, yes you can do exactly that… or are you saying that you’re done that and it’s not working correctly?

1 Like

thanks for the helpful info, @ed727 !

1 Like

@adamhholmes thanks for the reminder. I experimented with that feature once but ran into a few issues which prompted me to uninstall. Sounds like I should give it another look. Thanks again.