Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issue with lots of dynamic fields #21

Open
jmalley opened this issue Jul 16, 2018 · 8 comments
Open

Performance issue with lots of dynamic fields #21

jmalley opened this issue Jul 16, 2018 · 8 comments

Comments

@jmalley
Copy link

jmalley commented Jul 16, 2018

I have a matrix with a dynamic dropdown that pulls a large number of globals. It works fine until the user adds a lot of matrix blocks that all have this field in it, at which point the page is slow to load and times out frequently. It's going to the database a hundred times, presumably. Here's my code:

{ "value":"none" , "label":"N/A" },
{% for block in eventHost.eventLocations.order('locName').limit(null) %}
    { "value":"{{ block.locName }}" , "label":"{{ block.locName }}" }
    {% if not loop.last %},{% endif %}
{% endfor %}

What would be the best strategy for only loading this dropdown dynamically for the first block, and then displaying a cached or copied version of the dropdown for all the subsequent blocks. Is this even possible? Am I thinking about this problem in the right way?

@alexgilbertDG
Copy link

@jmalley Did you fix this issue ?

@jmalley
Copy link
Author

jmalley commented Nov 30, 2018

I don't believe so. I gave up and jacked up the memory craft is allowed to use. It's still slow, but I've gotten no timeout reports from the users at least. I'm also using an older version of this plugin with craft 2 so there may be another solution for the current plugin version.

@alexgilbertDG
Copy link

@jmalley Okay thanks, I got a similar issue. I will keep updating if I found a good/better solution.

@Tim-Wils
Copy link

@jmalley @alexgilbertDG

Does it work for you guys to cache the code? Like this:

{% cache globally using key "global-variables-in-dynamic-field" %} { "value":"none" , "label":"N/A" }, {% for block in eventHost.eventLocations.order('locName').limit(null) %} { "value":"{{ block.locName }}" , "label":"{{ block.locName }}" } {% if not loop.last %},{% endif %} {% endfor %} {% endcache %}

@alexgilbertDG
Copy link

I end up using a custom php cache solution so I can clear it on Event by Craft and exposed it with a twig variable. But I suppose it will work with this cache tag also !

@jmalley
Copy link
Author

jmalley commented Jan 26, 2019

That seemed to make a very noticeable difference, thank you! Is that just saving the dropdown values for future matrices after the first db request?

@Tim-Wils
Copy link

It's saving the dropdown-data template on the first request and re-using it at the next ones. I think there should be a clear-cache-plugin for named caches though, so that caches/named caches can be c;leared on save events. Maybe I'll look into that in a short while.

@jmalley
Copy link
Author

jmalley commented Jan 28, 2019

Ah makes sense. So I only need to cache it on the first instance of that dropdown in a page?

Let me know what you find out about the cache clearing if you don't mind. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants