uwazi icon indicating copy to clipboard operation
uwazi copied to clipboard

Overhaul entities saving / deleting processes

Open RafaPolit opened this issue 5 years ago • 2 comments

When saving or deleting entities, the process is very repetitive.

  • Functions like getByDocument of relationships are called numerous times, not reusing the values already extracted
  • Updating entities based on relationships can call the same entity 2, 3 or 20 times with the same exact data because the entity is present more than once in the relationships
  • The creation / deletion flow, if something fails, may end up with entities deleted but relationships still pointing to that entity

This last one requires some heavy restructuring: we need to think what is the correct order of things to happen. If you delete all the relationships to an entity, and, after success, you delete the entity, that never leaves 'unreachable' data. If you do it the other way around and first delete the entity, and the the relationships... you could end up with phantom relationships that have no way of being accessed or purged by the user.

This is currently accomplished with a Promise.all, which is the most efficient way: do everything at once, report back when finished. But this has proven to leave trash and bug-prone documents in the database. Perhaps we need to go back to a more 'lineal' process for these critical operations?

@txau @daneryl @konzz @RafaPolit

RafaPolit avatar Mar 27 '19 18:03 RafaPolit

Maybe fix with MongoDB 4 and transactions?

txau avatar Apr 15 '19 14:04 txau

Let's fix this with transactions.

txau avatar Apr 27 '22 16:04 txau