开发者

How to implement temporarily undoable operations in PHP and JavaScript?

开发者 https://www.devze.com 2022-12-24 05:44 出处:网络
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

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

精彩评论

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