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

**URL:** <https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267>\
**Category:** Questions about Thunkable X\
**Tags:** firebase, database, list, object\
**Created:** [January 20, 2021, 5:01pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267 "2021-01-20T17:01:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 20, 2021, 5:01pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/1 "2021-01-20T17:01:15Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/a/9afa87b14d17fc35ad6708c5fc6b8ed774faafb0.png)

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 22, 2021, 4:17pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/2 "2021-01-22T16:17:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [January 22, 2021, 4:19pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/3 "2021-01-22T16:19:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 22, 2021, 4:21pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/4 "2021-01-22T16:21:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 22, 2021, 6:34pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/5 "2021-01-22T18:34:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [January 22, 2021, 7:54pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/6 "2021-01-22T19:54:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 23, 2021, 12:32am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/7 "2021-01-23T00:32:46Z")

</div>

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/2/b205186511eb7edfddfeba5ecd820237eebcee7a.png)

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

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 23, 2021, 3:24am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/8 "2021-01-23T03:24:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [January 23, 2021, 5:23am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/9 "2021-01-23T05:23:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 23, 2021, 12:42pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/10 "2021-01-23T12:42:20Z")

</div>

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

How would you do it?

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 23, 2021, 1:39pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/11 "2021-01-23T13:39:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [January 23, 2021, 2:36pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/12 "2021-01-23T14:36:54Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/1/b174bbe04ed8ba691925b779f6f118a1883a5a42.png)

and so on.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 23, 2021, 4:41pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/13 "2021-01-23T16:41:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 24, 2021, 12:06am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/14 "2021-01-24T00:06:52Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/c/bca2732ed169c744caff3717dbd86eb38c49acb8.png)  
I’ve tried every combo of putting the get object and generate JSON plugged in, it either does nothing or it crashes.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [January 24, 2021, 4:29am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/15 "2021-01-24T04:29:11Z")

</div>

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:

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

```

But I’m guessing your actual structure is:

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

```

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

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 24, 2021, 5:28am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/16 "2021-01-24T05:28:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [January 24, 2021, 7:56am UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/17 "2021-01-24T07:56:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 24, 2021, 4:45pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/18 "2021-01-24T16:45:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![overshield](https://avatars.discourse-cdn.com/v4/letter/o/e19b73/32.png) [@overshield](https://community.thunkable.com/u/overshield)\
**Post date:** [January 24, 2021, 8:10pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/19 "2021-01-24T20:10:39Z")

</div>

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](http://community.thunkable.com/t/how-do-i-work-with-json/14498/7)

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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [January 24, 2021, 8:13pm UTC](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267/20 "2021-01-24T20:13:26Z")

</div>

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.

[Next page](https://community.thunkable.com/t/nested-for-each-item-j-is-very-slow-drilling-down-into-firebase-data/1060267.md?page=2)
