Closed zeeshanakram3 closed 4 months ago
Not sure whether I get the logic, previously we invoked
getNextIdForEntity
for multiple notifications and then incremented the row. Now we will increment it when each notification is being created, this way there arent conflicts?
No, there wont be any conflicts, because we are incrementing the ID and then reading it from the overlay (which is in-memory cache) and not db. So there is no asynchronous operation involved in update the id.
Context
While creating the runtime notifications addRuntimeNotification function reads the nextEntityId for the new notification from the db. And, then use this id to create a new entity in the overlay.
Now the problem is that if many concurrent notifications are being created e.g.
Promise.all([...])
. Then each concurrent call ofaddRuntimeNotification
will read the same next entity ID from the db, and only one notification can be created.Fix
Instead of using db to get the next entity ID, read the ID form the overlay and then update it too, so the each concurrent
addRuntimeNotification
instance has access to the correct next entity ID.