twomice / com.joineryhq.reltoken

CiviCRM extension: Provides tokens for any related contact, for all available contact tokens. E.g., to get the spouse's first name, or parent's marriage date.
Other
1 stars 5 forks source link

Performance/out of memory issue #3

Closed MegaphoneJon closed 5 years ago

MegaphoneJon commented 5 years ago

This extension calls CRM_Core_SelectValues::contactTokens() on line 9, which in turn invokes this hook, so it runs twice.

I know you know this because the static variable is meant to account for this in part. However, the loop that creates the "related" tokens is called twice, so it tries to create tokens of the tokens. This leaves the $tokens array with ~333,000 elements in my instance, which crashes with an OOM error.

I have a patch that only creates new tokens if the token starts with {contact, which yields ~5600 tokens, which is what was intended.

This prevents OOM errors when saving a contact record, but the Select2 widget is very slow. I intend to write a second PR that allows you to select the relationship types that get tokens. This should improve performance and make a better UX by not cluttering the token Select2 with unneeded tokens.