How ":defaulting to" works in terms of optimization

Hey gents, maybe someone knows the exact answer.

There is an expression like:

[expression_part_1]:defaulting to[expression_part_2]

Let’s say it is used to display a picture. First, we look at the required list; if there are no pictures there, then we load them from the default list.

Question:

Will Bubble load only the first part of the expression, and if it is empty, will it additionally request the second part of the expression (that is, Bubble works more optimized)
or
it will immediately evaluate both parts of the expression and then check if the first element is empty. (not optimized as lists can be huge with complex filters)
Thanks

Hello @misheglod Welcome to the community!

My understanding is that Bubble evaluates expressions lazily. This means that it should only evaluate part 2 if part 1 is empty.

1 Like

Yes, I hope so too.

Test and iterate … what we all do to get things working right? :wink:

Just out of curiosity I have decided to try this. I have created a text field and dynamically set the text of it from an open API endpoint (https://www.boredapi.com/api/activity) and defaulting it to another API endpoint in case the first one fails (https://catfact.ninja/fact). When I have analyzed the network traffic, bubble called both API end points even if the first one is visible succesfully.

image

The first API endpoint prints a random activity successfully.

And here is the second API endpoint call in the browser network even if it is not visible in the text field.

3 Likes

Cool to know! Thanks for sharing this @hergin !

Great job! :smiley:

It’s a shame that this is the result. :pensive:

I conducted the same experiment but with database queries. The result is the same. I’m sad. :broken_heart:



@grace.hong @nick.carroll

This behavior may be of interest to you

1 Like