"Merge" / disregard commits from multiple clients if same ID

Hi,

Is there a way to have one or more clients fire off a change nearly at the same time without it adding both commits?

The use case here is that all of my connected clients are listening to another web socket and when a change happens, they will change the ydoc. The problem is just that all clients will make the same change, so if you’re say adding something to an array, you end up with multiple added instead of the intended one added.

Hi @philipaarseth, That sounds very dangerous and impossible to implement correctly. So I’d say no. Maybe find an approach so that you don’t have multiple users performing the same change…

Thanks for the reply @dmonad
Why would it be dangerous?

The way I envisioned it working is you just have a function that would spit out the same string ID based on the change you want to do. Then you could filter externally incoming commits on that ID, perhaps with a timeout.

something like:
data change → stable & predictive ID → if incoming change ID is similar to something you’ve committed locally within x seconds: dismiss commit

As a sidenote, I guess this is possible to implement with another ymap.

{
  "changeID": data
}

Then apply those map values onto your actual data.

But yeah, I am continually looking for alternative approaches to this as I’m not happy with how it works currently. It’s too complicated and not very fun to maintain. Problem is really that I have a serverless function that modifies part of the data in the database. The same data is synced through a ydoc for high frequency changes without having to pay for a ton of DB writes. If someone is currently editing with yjs and none of the clients pick up the change in the database and take it into account, the data will fall out of sync.
If the serverless function didn’t need to execute very quickly I could have it making the change directly on the ydoc, but that would probably double or triple the execution time.

These changes are still applied in different execution contexts (e.g. browser windows). If one browser window inserts first “ABC” and then “XX”, but the other inserts first “ABC” and then “XX”, you will get into an invalid state (the generated lamport timestamps are different). Really, just don’t do it.