I have a question about locking. This doesn’t have to be only about record locking, but anyway.
Let’s say I’m writing a web accessible CMS. I am struggling with some ideas.
I could, on the moment when a user opens an article for editing, flag the article as being ‘in use’. so far so good.
but when do I remove the flag? when the user saves the article? but what if the user doesn’t feel like typing anymore and decides to close his browser and go to bed?
a time-out mechanism comes to mind, but how long does it take to write an article? 10 minutes too short, 30 minutes too long..
Maybe I am over-complicating this. I’d like to hear your thoughts on this subject.
Why not use timestamps? Don’t actually worry about locking anything, just react to the event where the record (article) has changed.
Basically, before you save the article, check if your version (timestamp) is the same as what is on disk. If same, then you still have latest copy so write it, if not then … offer to merge, offer to save as new, discard it – its application specific.