开发者

How to implement temporarily undoable operations in PHP and JavaScript?

I would like to implement operations that is undoable in a short time after the user have done them. I.e. if a user upvotes a photo in a photo-site, he/she can undo the vote within 30 seconds. This is similar to how the voting on StackOverflow is working, you can undo your votes for a short time.

How should I implement it? I guess that I shouldn't commit the votes to the database before the delay has timed out, for performance reasons. And it's hard to do it in JavaScript because then is the vote lost if the user change website before the delay has timed out. Maybe I could do it in cookies, or maybe the best s开发者_如何转开发olution is to do it in PHP Sessions, but How do I commit the operation after the delay then?


I suggest to yes, commit the vote with a timestamp into your database. It is a clean and easy solution. If you get performance problems, then you could use an in-memory database like sqlite as secondary backend to your vote data layer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜