Increase filter performance

Hi folks :slight_smile:

I’m working on a website whose purpose is to archive a large quantity of micro-publications.

I currently want to set up a page where users can filter all the publications with ‘city’ ou ‘country’ parameters. To do that I read the topics about filtering by tags etc and all is working !

But actually I’m struggling with the performance… Indeed, the website page takes about 4 seconds to load because of the large amount of publications to search in – about 8000 at the moment.

Here is the code I use in my controllers/publications.php

    if($tag = param('pays')) {
        $publications = $site->index()
                        ->children()
                        ->search($tag, 'origine')
                        ->listed()
                        ->paginate(50)
                        ->filterBy('template', 'publication');
    } elseif ($tag = param('ville')) {
        $publications = $site->index()
                        ->search($tag, 'ville')
                        ->listed()
                        ->paginate(50)
                        ->filterBy('template', 'publication');
    } else {
        go(url('error'), 301);
    }

	return compact('tag', 'publications');

Can I do better to increase these bad performances …?

Thanks a lot !

Zellda :slight_smile:

Going through the complete index is always a problem on large sites and using something like the boost plugin might be an option to improve performance.

Apart from that, the order of your method calls is weird and should be

$site->index()
    ->listed()
    ->filterBy('template', 'publication')
    ->filterBy($tag, 'ville', ',')
    ->paginate(50);

I will check the plugin !

Thank you for your answer :slight_smile: yes the order was a bit weird… I’ll correct that !

Forgot to post the link:

1 Like