Do not create smarty cached templates for processed greetings #16733
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Currently whenever a greeting is parsed through smarty a smarty template file is stored to disk. This has
impacts on disk use, cache clearing time and performance. Where we know that the template will be of low value so this uses the {eval} (not the evil eval) to only create one cache file for all singleUseStrings
Before
For every edited contact smarty files are created for each greeting - note post #16731 this only applies to contacts with smarty in greeting fields - eg. alter postal_greeting under administer->communications to
{contact.first_name}{if 1===1} the bold {/if}
After editing a contact their postal greeting should have 'the bold' (good) AND there will be a file created somewhere in templates_c with the compiled template for that contact (bad)
After
The commits that are also in
#16731 make it so smarty is only parsed if there are smarty tags. If it is parsed only one smarty template is created for ALL the contact greeting strings.
User experience should be the same but going into templates_c & doing
ls -R * | grep .php
should show no new created filesTechnical Details
This tries to replicate the smarty3 approach somewhat in Smarty2
Smarty3 which we are alas not using directly allows specification of 'eval' which means 'like a string but don't cache' https://www.smarty.net/docs/en/resources.string.tpl
In order to replicate that in Smarty2 I'm using {eval} per
https://www.smarty.net/docsv2/en/language.function.eval.tpl#id2820446
From the above:
Comments
Test already added in #16731
I started out working through this
civicrm/civicrm-packages#234 by @sunilpawar
but I was uncomfortable on 2 fronts