<p>I'm trying to show the nutrition information for restaurants using the following snippet</p>

<pre><code>                    {% set nutrition = craft.entries.section('nutrition').Ids() %}

                    {% set entries = craft.entries ({
                        section: 'restaurants',
                        orderBy: 'title',
                        limit: 50,
                        relatedTo: nutrition
                    }) %}
</code></pre>

<p>The nutriton channel has around 300k entries and around 200k entries in restaurants channel. Dedicated server with 16gb ram and 8 vcpus can't really handle it. Load average is above 4 and CPU utilization by mysql is 100%-300%. Page loads forever with 550 ram used according to dev toolbar.</p>

<p>Is there a way to speed the things up?</p>

CC BY-SA 4.0
2020-05-09T02:21:14.337Z
I think we'll need to know a bit more about the results you're expecting, in order to guide you... it looks like you're just trying to find the first 50 restaurants that have _any kind of nutrition information_ associated with them?
August Miller
CC BY-SA 4.0
2020-05-09T12:57:47.600Z
Correct. The goal is to display restaurants that have nutrition data associated with it.
Mark H.
CC BY-SA 4.0
2020-05-11T03:58:58.867Z
How are the restaurant entries being related to the nutrition entries? Depending on how you're relating them, would [``:notempty:``](https://docs.craftcms.com/v3/entries-fields.html#templating) work on the related field instead? That would eliminate having to pull down 300K entry IDs right off the bat...
RitterKnight
CC BY-SA 4.0
2020-05-11T11:12:29.757Z
They are not related. Nutrition entries have "entries" field pointing to the proper restaurant instead.
Mark H.
CC BY-SA 4.0
2020-05-11T19:33:10.460Z
Mark H: But they are related "the other way around" (that is, the nutrition entries point to or relate to the restaurant entries).  Are there nutrition entries that don't point to any restaurant? If so you can help Craft save some CPU by only querying for the IDs that point back to restaurants.
RitterKnight
<performance><speed><optimization>
Optimize heavy query
# Optimize heavy query

(Asked by: username_0 on 2020-05-09)

I'm trying to show the nutrition information for restaurants using the following snippet
                    {% set nutrition = craft.entries.section('nutrition').Ids() %}

                    {% set entries = craft.entries ({
                        section: 'restaurants',
                        orderBy: 'title',
                        limit: 50,
                        relatedTo: nutrition
                    }) %}

The nutriton channel has around 300k entries and around 200k entries in restaurants channel. Dedicated server with 16gb ram and 8 vcpus can't really handle it. Load average is above 4 and CPU utilization by mysql is 100%-300%. Page loads forever with 550 ram used according to dev toolbar.
Is there a way to speed the things up?

**Tags:** performance, speed, optimization

> **Comments:**
> **username_1**: I think we'll need to know a bit more about the results you're expecting, in order to guide you... it looks like you're just trying to find the first 50 restaurants that have _any kind of nutrition information_ associated with them?  
> **username_0**: Correct. The goal is to display restaurants that have nutrition data associated with it.  
> **username_2**: How are the restaurant entries being related to the nutrition entries? Depending on how you're relating them, would [``:notempty:``](https://docs.craftcms.com/v3/entries-fields.html#templating) work on the related field instead? That would eliminate having to pull down 300K entry IDs right off the bat...  
> **username_0**: They are not related. Nutrition entries have "entries" field pointing to the proper restaurant instead.  
> **username_2**: Mark H: But they are related "the other way around" (that is, the nutrition entries point to or relate to the restaurant entries).  Are there nutrition entries that don't point to any restaurant? If so you can help Craft save some CPU by only querying for the IDs that point back to restaurants.  

---

## 0 answers

