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

(dev/core#5243) mixin/smarty - Reduce expensive calls to getTemplateDir()/setTemplateDir() #30281

Merged
merged 1 commit into from
May 30, 2024

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Follow-up to #30148 to address https://lab.civicrm.org/dev/core/-/issues/5243 identified by @eileenmcnaughton. (This is one possible resolution - suggested by @totten.)

Before

  • The smarty mixin registers hook_civicrm_config -- with one listener on behalf of each extension. On Smarty 3/4/5, this listener calls getTemplateDir(), prepends its own template-dir, and calls setTemplateDir().

  • Everytime an extension calls getTemplateDir(), it forces a full (re)normalization of the directory-list (to sync-up with the prior addition)... which examines all the directories that we're previously registered.

After

In effect, this is a refactoring that moves the per-extension listeners from hook_civicrm_config to an internal event (civi.smarty-v2.addPaths.XXX). Specifically:

  • The smarty mixin registers for civi.smarty-v2.addPaths.XXX(array &$dirs) -- one listener on behalf of each extension. Each listener prepends/enqueues its own extension (array_unshift($dirs, $dir)).

  • The smarty mixin registers a single listener for hook_civicrm_config. It serves as an adapter. It fires the internal event (civi.smarty-v2.addPaths.XXX(array &$dirs)), gets a list of all template dirs, and applies one update to $smarty (getTemplateDir() + array_merge() + setTemplateDir()).

  • You only need to (re)normalize the directory-list one time.

Copy link

civibot bot commented May 29, 2024

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label May 29, 2024
@eileenmcnaughton eileenmcnaughton changed the title mixin/smarty-v2 - Reduce expensive calls to getTemplateDir()/`setTe… (dev/core#5243) mixin/smarty - Reduce expensive calls to getTemplateDir()/setTemplateDir() May 29, 2024
@eileenmcnaughton eileenmcnaughton changed the base branch from master to 5.74 May 29, 2024 19:58
@civibot civibot bot added 5.74 and removed master labels May 29, 2024
@eileenmcnaughton
Copy link
Contributor Author

@totten I'm happy with this based on my testing - technically the PR is showing as 'mine' but it's your commit - I'll give it merge-ready now but hopefully only briefly as I'm wanting to deploy the updated rc tarball with this & some other Smarty patches (I will check their merge status)

@eileenmcnaughton eileenmcnaughton added the merge ready PR will be merged after a few days if there are no objections label May 29, 2024
@totten
Copy link
Member

totten commented May 29, 2024

I'm gonna plug this into a civix-backport and make sure that works.

@totten
Copy link
Member

totten commented May 30, 2024

Did some more testing on civix backport. Tldr: Seems good. (Full details are listed on that PR.)

Since all of this started with civicrm/org.civicrm.contactlayout#143, I decided to go back retest that. Seems good. (Specifically, I started on 5.73.1 and confirmed the original "Summary"<=>"1" problem -- then copied over the proposed version of smarty-v2 ... and the problem went away!.)

@eileenmcnaughton
Copy link
Contributor Author

it's like magic

@eileenmcnaughton
Copy link
Contributor Author

Merging as that is what I think the intent of the above comment was

@eileenmcnaughton eileenmcnaughton merged commit 6da971f into civicrm:5.74 May 30, 2024
1 check passed
@eileenmcnaughton eileenmcnaughton deleted the 574-totten branch May 30, 2024 05:27
Comment on lines -36 to -38
// Add the dir if not already present
if (!in_array($dir, $templateDirs, TRUE)) {
array_unshift($templateDirs, $dir);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uniqueness check seems to be missing from the new version...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.74 merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants