4

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?

0

3 Answers 3

3

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...

2
  • Do you have any suggestions on jQuery code to create the AJAX (Update locking_timestamp) based on a counter? I'm sure this has been done before.
    – jjwdesign
    Feb 22, 2013 at 18:36
  • @jjwdesign, just use the setInterval function of javascript to execute your AJAX calls periodically.
    – linepogl
    Feb 22, 2013 at 20:15
1

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 .

1
  • I'm not sure I'll be able to implement it, because many this systems users are slow to process much on the page. Much of it is research related. But, thanks for the concept ideas.
    – jjwdesign
    Feb 22, 2013 at 2:05
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.