I'm finding that if I use a module tag like stash or playa as a parameter in a plugin tag, that an extra query for the module name is run for each loop. Here's the query that's run:
SELECT `module_version`, `module_name`
FROM (`exp_modules`)
From what I can tell, it's EE looking up the module so that it can parse it's tags. Here's some example template code that's generating the extra queries. This example uses a channel entries loop and a playa tag as a parameter but using another module tag like stash with just a string of ids 1|2|3|4
will do the same thing. The sp_within
plugin is a custom plugin I've written however I've tried this with other plugins and the same thing occurs.
{exp:channel:entries channel="professions" orderby="title" dynamic="no" sort="asc" disable="custom_fields|categories|member_data|pagination"}
{exp:sp_within haystack='{exp:playa:child_ids field="member_profession" entry_id="{zoo_visitor_id}"}' needle='{entry_id}' parse="inward"}
<label><input name="member_profession[selections][]" value="{entry_id}" type="checkbox"{if within} checked="checked"{/if}> {title}</label>
{/exp:sp_within}
{/exp:channel:entries}
I'm using the stash template partials approachEdit Here's a clearer example that just uses a channel entry loop and have optimised my templates to reduce the required number of queries which is why I noticed the additional queriesa stash variable.
{exp:stash:set name="selected_ids"}94|2|45|87{/exp:stash:set}
{exp:channel:entries channel="professions" dynamic="no" disable="custom_fields|categories|member_data"}
{exp:sp_within haystack='{exp:stash:selected_ids}' needle='{entry_id}' parse="inward"}
<label><input name="member_profession[selections][]" value="{entry_id}" type="checkbox"{if within} checked="checked"{/if}> {title}</label>
{/exp:sp_within}
{/exp:channel:entries}
Can I cache the query for the module name in my sp_within plugin? It's okay when there's only a few extra queries but it gets a bit ridiculous when there's 20 plus. Does anyone know how to remove the extra queries?