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?

  • 2
    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? May 9, 2020 at 2:21
  • Correct. The goal is to display restaurants that have nutrition data associated with it.
    – Mark H.
    May 9, 2020 at 12:57
  • How are the restaurant entries being related to the nutrition entries? Depending on how you're relating them, would :notempty: work on the related field instead? That would eliminate having to pull down 300K entry IDs right off the bat... May 11, 2020 at 3:58
  • They are not related. Nutrition entries have "entries" field pointing to the proper restaurant instead.
    – Mark H.
    May 11, 2020 at 11:12
  • 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. May 11, 2020 at 19:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.