Refactoring of data loss system
Imported From: http://groups.google.com/group/in-portal-dev/browse_thread/thread/5e8a9ca61c9267e6#
We have data loss prevention system, that consists of several parts (all only in administrative console):
- [on by default] Data from tables being edited not directly, but via temporary tables created for each user individually (when user clicks "Add"/"Edit" buttons). When user clicks "Save" button on editing form, then data is copied back from temporary table to original live table.
- [off by default] When user clicks "Edit", then we are checking, that given record(-s) is not being edited by another user already and we are showing warning message to the user about that, so he can immediately cancel editing to prevent possible data loss
- [on by default] when user clicks "Save" button on editing form we are locking table, so nobody else in that moment couldn't overwrite data user is saving right now
Here I will be talking only about #2 item.
Currently it (#2) is implementing by scanning all temporary tables in database and searching our record ID in them. In case, when there are several administrators adding/editing data all the time, then you will have a lot of temporary tables at the end. Idea of refactoring is to create table, where all items, that are being edited (not added) right now are listed. So instead of database scan we will need only to execute select to that table. Of course we need to add more code to properly update data in that table, so it will be actual in any moment.
Original idea by Sergey.