Question

I've been thinking about developing some simple record locking for an application I'm involved in. There are a few users who will take literally hours to complete an edit of a record. This causes issues when someone else wants to make a change to the record. Currently there is no locking involved.

I'm not certain that Optimistic locking is reliable in my case, as the record is saved thru an AJAX request. I'm looking at applying some kind of Pessimistic Locking; using two fields, such as, locking_user_id and locking_timestamp, I can track who has the record open and the last time it was opened.

But, since the user may have it open for hours at a time, how can I know if the user abandoned it or is just working hard on it? I don't want to force them to update it every 5 minutes ~ yet that might be a possibility (AJAX save every 5 min).

Perhaps a jQuery process could be counting while the user works and would fire off an AJAX request (getJSON) every 5 minutes to update the locking_timestamp. That way I could maintain who is working on the record. After the timestamp gets "old", I can assume the user is no longer working with the reocrd. Has anyone had experience with this kind of locking?

Was it helpful?

Solution

Updating the locking_timestamp with AJAX requests is a fine strategy and will work out fine.

However, 5 minutes interval between the calls seem a little long to me. Unless you have really high traffic, something like 30 seconds would be better from a user's perspective. Imagine someone having to wait 5 minutes because another user opened the record and then closed his browser...

OTHER TIPS

Perhaps I'm being silly but how about having jQuery monitoring mouse and keyboard events on the page.

PHP places lock somewhere in filesystem or some flag on database entry so the next user will not be able to edit but just view the information. The file would contain the user information in the entry so when changes are sent only his changes are accepted

While the first user has activity on the page nothing happens. 3 minutes of the user not doing anything and he will be prompted to either confirm that he still is working on it or he will within 3 minutes loose his current changes. If he confirms nothing happens but if he does not Ajax will remove the lock .

If you say users could take several hours before submitting a record, then a simple 5 min lock or whatever wouldn't be sufficient.

Instead, why don't you implement a sort of check in/ check out feature which would be activated (checked out) on the edit of a record and "kept alive" at regular intervals, and deactivated (checked in) when the record was saved/ session expired/ browser closed/ etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top