SingleEdit: Prevent concurrent edits on records.
Posted: 2021-01-15 17:32
Hi,
I created a new extension which should be easy to implement: SingleEdit
Purpose: Prevent concurrent edits on records.
As AppGini (AG) in the current version 5.92 does not support locking records for user B if user A currently edits them, I decided to make a start.
From the docs:
Introduction
A common problem working with online-databases is, that it’s almost impossible to handle concurrent edits on the same record.
If user UA has record RA open in the browser, nothing prevents user UB from opening that same record RA in his browser. So far there is no problem, as user UA and user UB are only viewing the record. A problem arises, once both users start editing the record.
This might seem not so common, but people might keep their browser window open, do something else and try to save an edited record 30 minutes after they opened it. We, as developers, just do not know if the user is viewing, editing, has his browser closed etc.
Let’s make an example and assume the records shows customer’s C1 data: Customer’s C1 lastname, firstname and street address. The data in the database reads as follows:
UA not starts editing the record and changes the lastname because the customer C1 has married, so the data in the browser of UA is now:
At the same time UB changes the street address because the customer C1 has moved, so the data in the browser of UB is now:
We need do keep in mind every user sees the values on screen as they have been pulled from the database when the page was generated. This UA does not notice (yet), that UB changes the streetaddress and UB does notice the changes of the column lastname by UA.
UA now presses the save changes button in the browser window. The values that will be written to the database, overwriting existing values, are:
Once UB presses the save changes button in the browser window. These values will be written to the database, overwriting existing values:
We can now see the problem: The data has been messed up and is wrong. The user has his old lastname but the new streetaddress. The new lastname which UA had changes was overwritten by the old lastname when UB saved the values from his browser window.
User UB should not have been able to save his edits, but should have been notified, that the records has been changed in the meantime.
This script solves this problem.
It can look like this: Download v0.9
(.ZIP, size 237kb, including files and documentation)
https://dl.olaf-noehring.de/?t=167959be ... 3be10084cb
Comments? Ideas? Suggestions?
Olaf
I created a new extension which should be easy to implement: SingleEdit
Purpose: Prevent concurrent edits on records.
As AppGini (AG) in the current version 5.92 does not support locking records for user B if user A currently edits them, I decided to make a start.
From the docs:
Introduction
A common problem working with online-databases is, that it’s almost impossible to handle concurrent edits on the same record.
If user UA has record RA open in the browser, nothing prevents user UB from opening that same record RA in his browser. So far there is no problem, as user UA and user UB are only viewing the record. A problem arises, once both users start editing the record.
This might seem not so common, but people might keep their browser window open, do something else and try to save an edited record 30 minutes after they opened it. We, as developers, just do not know if the user is viewing, editing, has his browser closed etc.
Let’s make an example and assume the records shows customer’s C1 data: Customer’s C1 lastname, firstname and street address. The data in the database reads as follows:
Code: Select all
Lastname: Noehring
Firstname: Olaf
Streetaddress: Somestreet 3
Code: Select all
Lastname: Merkel <--- the value has been changed by UA
Firstname: Olaf
Streetaddress: Somestreet 3
Code: Select all
Lastname: Noehring
Firstname: Olaf
Streetaddress: Countryside 99 <--- the value has been changed by UB
UA now presses the save changes button in the browser window. The values that will be written to the database, overwriting existing values, are:
Code: Select all
Lastname: Merkel <--- the value that has been changed by UA
Firstname: Olaf
Streetaddress: Somestreet 3
Code: Select all
Lastname: Noehring
Firstname: Olaf
Streetaddress: Countryside 99 <--- the value that has been changed by UB
User UB should not have been able to save his edits, but should have been notified, that the records has been changed in the meantime.
This script solves this problem.
It can look like this: Download v0.9
(.ZIP, size 237kb, including files and documentation)
https://dl.olaf-noehring.de/?t=167959be ... 3be10084cb
Comments? Ideas? Suggestions?
Olaf