Best way to increase performance when building navigations and using `toPages()`

When building navigation menus and places in the panel, to configure it, we might be used to set it up via a pages field. That also means, in the frontend, that we are going to use toPage() or toPages() to be able to get the url() and the title().

Now I hit a performance bottleneck with that, and I’m not quite sure what the approach is to solve it.

I have a page models that pulls data from an MySQL database to create the children. This whole process, especially because I have to sort stuff before getting it to the frontend, is increasing the server response from 170ms to 1.30s. I could probably cache better or see if I can somehow index the ORDER BY stuff in the database, as this is one of the bottlenecks.

However, as I have this page with its page model in the navigation, the data of the database, and therefore the slow part, is requested on every page, as, I assume, the toPage() and toPages() function in the navigation makes sure, all data, including the children, are available.

I wondered if any of the features, like collections, or using the cache, is the right solution to this. Or if there is anyway I can make the toPage()/toPages() in a way, it only retrieves the title and the URL, the two things I actually need for the navigation to work. Because I don’t need the ‘children’ there, nor do I need the content of the page itself.

1 Like