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.
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?
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.
@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?
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.
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:
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.
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.