Hello,

I have a Flag set up to flag users (follow user), and a rule setup to email the flagged user when they are flagged (followed by users).

The flag is set to javascript toggle, which is now extremely slow after adding this email rule to the flag. When clicking the flag, it takes a long time to load, presumably from the rule setup.

Is there anyway to increase the speed at which the user sees the flag as "flagged" state? i.e. anyway to set the flag so that upon click, jQuery or something is used to change the state of the flag to "flagged" while the background process sends information to the database and runs the rules?

Any help is greatly appreciated!!

Comments

joachim’s picture

Category: feature » support
Status: Active » Fixed

> and a rule setup to email the flagged user when they are flagged

My guess would be that it's the sending of the email that causes the ajax request to take so long.

> anyway to set the flag so that upon click, jQuery or something is used to change the state of the flag to "flagged"

That's not possible because the ajax callback checks whether the flagging action is valid.

The way to handle this would be if there's a way to schedule the email to send later, such as on a cron run. I don't know enough about Rules to know if that's doable though. Certainly could be done in code with a hook implementation to react to the flagging.

Jessica A’s picture

Project: Flag » Rules
Version: 7.x-2.0-beta7 » 7.x-2.1
Component: Flag core » Rules Core
Status: Fixed » Active

Moving this to the Rules project.

Is there any reason why adding a rule to send an email causes such a large performance hit? Any way to speed this up? Thank You!

joachim’s picture

Because sending email is a slow operation for the server to perform.

mitchell’s picture

You could try using Rules' Queue API integration (Rules Scheduler). Hypothetically, you could modify your "Send [x] email to user [y]" component to "Schedule sending [x] email to user [y] at [z]" (with [z] being 'now' for ~immediate sending). As long as you have Rules' cron jobs configured to run in short intervals (eg, Elsyia Cron), then sending will take place almost immediately.

More discussion:
* If you also want to look at how Rules could push Drupal to run cron jobs instead of polling for them, we can do that too.
* I'd be interested to see how you've configured this setup. Would you be interested in posting this to a sandbox? I mocked up a similar, yet admittedly, more complex system not that long ago, Track N Notify. I always find alternative solutions to be motivating, and d.o is configured much like your solution.

Jessica A’s picture

Hi Mitchell,

Do you know anywhere I can find a tutorial on how to use rules scheduler to achieve what you are describing? I've looked around rules "schedule" and it's really confusing. :(

For the email notification, all I did was add a user profile field for checking if the user would like to receive an email. From there I just set up an event for posting a new comment, then used data validation to check whether or not the user has "Yes" or "No" chosen in their email profile settings field. Then the rule's action is set to send an email.

Due to the rule sending an email, it slows down the flag module, which may cause the user to click twice. If what you describe with rules scheduler can be achieved, I think it would solve this issue.

Thanks Again!
-Jessica

mitchell’s picture

Status: Active » Postponed (maintainer needs more info)

Jessica, check out Rules Scheduler Basics, and if you haven't made the leap yet into using components, then start with the introduction to Components.

If it's no trouble, your feedback on how it goes using that info would be really helpful. I'll leave this issue open for you to let us know if this is actually solved. Good luck!

Jessica A’s picture

Okay,

So I've made a component, action set, to send an email to the flagged user, and then set my rule to schedule component evaluation.

An error occurs when trying to send an email to "[flagged-user:mail]" it seems the token is not working.

Any suggestions? Thanks again!~

TR’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (outdated)

If you continue to have a problem with this in the current version of Rules please open a new issue.