views:

38

answers:

1

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 solution is to do it in PHP Sessions, but How do I commit the operation after the delay then?

+3  A: 

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.

erenon
I'd second this. Most things will probably not get undone, and even if everything got undone, that'd only be 2x the load of no undo's at all. K.I.S.S.
Amber
Thanks for your advice. So you suggest that I do a DELETE-query on Undo, and that's it. And maybe check the timestamp both by JavaScript and by the WHERE-part of the DELETE-query. Hm, that could be an efficient solution.
Jonas