Client server array discovery optimization or design pattern

What method do you use when you want to detect server-side changes in an array sent by the client?

eg. a very simple scenario, we have an array Persons, the client side receives it from the server and modifies it in three ways.

  • Adds a new one.Person
  • Updates existing Person(change name)
  • Deletes Person

and sends the array to the server, which is responsible for storing it in Database, but first, it must detect incoming changes and save them. I am currently detecting incoming changes using this approach:

  • Items without margins Idare considered added.
  • Items that are missing on the client side but only on the server side are considered Deleted (I find that it compares the fields Id)
  • Elements that are present on both sides (re-discovered when comparing fields Id) are considered Updates

The first two are fine, since there are a small number of elements (detecting a Deleted object would be inefficient in an array, for example, 10 thousand elements, etc.).

Another approach that I think of, but have not tried, is to Add an additional field to ViewModels , sent by the client to the server, which can have three values Added, deleted, updated .

? , .

+4

All Articles