As far as I know, a general solution to the problem does not exist.
The root of the problem is that the user can retrieve data and look at it on the screen for a long time before doing the update and saving.
I know three main approaches:
When the user reads the database, lock the record and do not release it until the user has saved any updates. In practice, this is wildly impractical. What if the user opens the screen and then dines without saving? Or is he going home for a day? Or is he so upset, trying to update this stupid record, that he leaves and never comes back?
Express your updates as delta, not recipients. To take a classic example, suppose you have a system that registers inventory in inventory. Each time you sell, you must subtract 1 (or more) from the inventory account.
So say that the quantity is currently 10. User A creates a sale. Current quantity = 10. User B creates a sale. He also gets the current quantity = 10. User A enters two blocks sold. New quantity = 10 - 2 = 8. Save. User B is included in one sold unit. The new number = 10 (the value that it downloaded) - 1 = 9. Save. Obviously, something went wrong.
Solution: instead of writing "update inventory quantity = 9, where itemid = 12345", write "update inventory quantity = quantity-1, where itemid = 12345". Then give the database a queue of updates. This is very different from strategy No. 1, since the database only needs to record a record long enough to read it, make an update and write it. He does not have to wait while someone is looking at the screen.
Of course, this can only be used for changes that can be expressed as delta. If you, say, update a customer’s phone number, it will not work. (For example, the old number is 555-1234. User A says to change it to 555-1235. This change is +1. User B says to change it to 555-1243. This change is + 9. So the total change is +10. the new client number is 555-1244. :-)) But in such cases, "the last user who clicked on the win key" is probably the best thing to do.
- When upgrading, make sure that the appropriate fields in the database match your "from" value. For example, say you work for a law firm that contracts for your clients. You have a screen where the user can enter notes on the negotiations. User A creates a contract entry. User B creates the same contract entry. User A says that he was just talking to the other party over the phone, and they agree with the proposed conditions. User B, who also tried to call the other party, states that they do not answer the phone and suspects that they are obstructed. User A clicks the Save button. We want user comments B to rewrite user A? Probably no. Instead, we display a message stating that the notes were changed after he read the record and let him see the new value before deciding whether to continue saving, interrupt, or enter something else.
[Note: the forum will automatically renumber my numbered lists. I'm not sure how to override this.]
Jay Aug 29 2018-11-11T00: 00Z
source share