Quantcast
Viewing all articles
Browse latest Browse all 49206

Organising rules for efficient execution

I'm getting the hang of writing custom actions but I need some help in how to execute a number of rules together into a workflow that doesn't slow my site down too much.

I have a number of custom actions executed on the event 'After saving new content' with a condition of 'Content has type'.

The actions include:

  • Load 2 referenced nodes
  • Calculate & write new cck field values into these referenced nodes
  • Send emails to multiple users

All actions work as expected but I do have a slight performance problem with my 'Send emails' action. I'm not using contrib messaging modules to send email but just using the drupal_mail() function. This is a lightweight & simple to use function for my purposes (I am adding to the weight a bit by using htmlmail).

I'm building the list of users to mail to by running a db_query based on values from my loaded referenced nodes. I'm also customising the email body using values returned in this query. I'm then looping through the list and executing drupal_mail() against each user. As you can imagine this takes a bit of time but in itself the couple of seconds it takes is not the problem.

However because the email action is triggered from the same event that also writes values and saves to my content nodes, the user is not returned to a node view page until the drupal_mail functions have executed.

What I really want is that my custom node updates complete quickly and the user is returned to a view of their node page. Meantime (in the background) drupal_mail gets to work sending the emails.

What would be a good way to achieve this using Rules?
(I'm looking at sets and schedules - but some reason I cannot get my head round it this afternoon!)

Thanks for any advice.


Viewing all articles
Browse latest Browse all 49206

Trending Articles