Nested for each item j is very slow; Drilling down into firebase data

I have nested for each item j’s and it’s very slow.

It’s only 2 levels in but it’s too slow to be a viable product.

Am I likely overlooking something or can someone show me an example of a fast working nested item j?
My current project has 6 categories in the first list of item j
Then below that each of those categories has about 25 subcats.

It takes approx 3-4 seconds to get through the first category + first 25 subcats.
Multiplying by all 6 categories ends up taking around 20 seconds to do all 151 subcategories in total.

Here’s my stack

Well I’ve now learned it wasn’t due to the item j’s being nested. The problem is just cycling through each object and returning the property. Does anyone have a suggestion that would make this process faster?

1 Like

The actual problem is not cycling through the objects. The main delay comes from the way you retrieve info from the database. This is the bottleneck of the whole process.

Happy Thunking

1 Like

Hi @muneer, your input is always welcome, could you provide an example of a way to retrieve it differently?

@muneer I’ve considered retrieving the data sooner in the screen instead of waiting on a button push, but this data specifically needs to be retrieved upon request at that moment.
Do you have a suggestion that would make this process faster?

1 Like

You need to notice that every time you query for data you are actually making an internet request to obtain this data from Firebase.

So the idea is instead of querying small pieces of data from Firebase over the internet in every iteration of your loops, better to obtain one big chunk of data at first and assign it to an app variable and use it in your loops.

For example, at the start of the button click event retrieve “top level” from the database and save the result into an app variable either as object or as JSON text.
Your loop should now work with the app variable instead of the cloud variables. This way your loops will finish in a second or less.

Here’s what I’ve got so far, the app crashes on list viewer item click

Seems I don’t know how to drill down into further levels using this method where I generate JSON from object and then store it to a variable.

Could I see an example?

The item green block of the list viewer is a simple text and not a JSON object and therefore it will crash if you try to use it as object.

With a cloud variable I can type out the path, I can’t do that in an app variable.

How would you do it?

What I mean is in a cloud variable I can type toplevel/2ndlevel/3rdlevel… and so on until I get where I want.

But once I’ve saved the entire chunk of data to an app variable I don’t know how to navigate it.

1 Like

If you save the cloud content in an app variable as an object then you can refer to it as:

and so on.

1 Like

So you can’t drill down in a list without first knowing how many levels there are to begin with?

Hmm, there seems to be some missing parts to this then… here’s what I’ve got but it’s crashing still…


I’ve tried every combo of putting the get object and generate JSON plugged in, it either does nothing or it crashes.

Can you post a screenshot of the firebase data?

It looks like you’re trying to take the property “overshield” from the cloud variable “overshield”. So that would mean your firebase data structure would be:

overshield
   - overshield
      - top level
         - 2nd level
            - 3rd level

But I’m guessing your actual structure is:

overshield
   - top level
      - 2nd level
         - 3rd level

And that the first property you should get from TempList is “top level”.

1 Like

Yes the structure is the same as your 2nd screenshot.
But I’ve tried it both ways with the blocks.
It still bricks the app or does nothing depending on the configuration.

I wouldn’t think it’s this hard to drill down into data from a list or whatever. Just need to see a working setup instead of little pieces so I can learn.

Drilling down into firebase nodes is ridiculously easy. It’s just a matter of using a cloud variable with the correct path as the name, such as overshield/top level/2nd level/3rd level. But getting the entire firebase dataset and then manipulating it as JSON is trickier.

I don’t have a solution at this point partly because my project preview seems to be buggy and it’s taking forever to try different methods.

1 Like

Ya I meant drilling down once it’s been saved as a JSON or object.

Once I realized this isn’t really a nested for item j problem I figured I would look elsewhere. That’s why I posted here - How do I work with JSON? - #7 by overshield

I saw it was actually related to what my problem was.
Well hopefully I’ll have a resolution soon.

I understand but the conversation about drilling down was already started here which is why I’m recommending it continue here. I changed the topic title to reflect that.