0

I have a number of action a user can preform in a social network website, like adding friends following people and such.

Now these actions are done by Ajax, and the user could easily undo them(when say following someone, the follow link is turned into unfollow and clicking it again -of course- results in unfollowing the user, and it -the link- turning back into follow).

When these actions occur, the user (being followed) is notified by via email. and the code that sends the email is run in the same ajax call. That results in two problems, one is that the email is sent even if the user decides to unfollow the other person at once. And two, multiple emails are sent if the user hits the follow/unfollow link multiple times.

I thought of using a session variable to store users'actions and then at "some point" check on that variable and preform accordingly. My struggle is in finding that "some point", thought of when the user logs out, but I can't guarantee that the user will actually log out.

any suggestions?

4

1 回答 1

0

我能看到的最简单的方法是:

在数据库表中推送通知。此外,对于用户,有最后一个活动列。经常检查之前发生的通知中的任何行,(user.last_activity + TIME_CONSTANT)从表中弹出它们,对它们进行分组,然后发送给用户。

“经常”可以是一个 cron 任务,甚至是每个请求(因为查询会非常简单和快速)。

于 2013-08-15T01:22:41.957 回答