Currently I have an Angular2 app that has an object with nested objects contained in it. The user follows a wizard to update any sections of the object and then clicks save. At the moment, I just send the entire object to the server side to be updated. To do the update, I get the database copy out of the DB and just set all the fields that the client copy has onto the database copy regardless of whether they have changed or not and then save it. This means I also have to loop through all of the nested objects and pull them out of the database and set all of their properties and so on. Everything gets updated, even if it didn't get changed.
This is they way I normally do it, but for this app I need to keep an audit log of objects that were changed. And it would be hard if every time the main object got updated, every other child object logs it was updated as well.
Is there an elegant way to make sure the server side knows only to update the things that have changed (and therefore only triggers the audit log for that object AND doesn't waste time making updates on the DB).
I was thinking about creating an object that stores a list of dirty objects on the client side as the user changes things in the wizard and sending it to the server along with the object so I know which objects NEED to be updated.
Or should I send the entire object to the server like I am doing now, and compare it to the original database object (by looping through all of the objects and comparing them) first to determine what has changed?
It seems like a lot of work. I was wondering if there is a standard way/best practice for doing this.
Aucun commentaire:
Enregistrer un commentaire