RTKQ: Optimistic Create #3953
Replies: 1 comment
-
Alright, I did some tinkering and can now say: Yes there are race conditions, as accessing state.api.queries is resolved now but dispatching is resolved later. This means it's useless for bulk operations as all these operations are executed now, current items are read for all operations and later executed, so only the last item is actually added. It takes quite long for bulk operations (creating more than 100 items at once). |
Beta Was this translation helpful? Give feedback.
-
I wanted to implement an optimistic create approach similar to optimistic updates and encountered some peculiarities with which I hope you can help me with.
Projects was just my playground to test the functionality, I'll use the results for an entity type that potentially has tens of thousands of entries.
As in other questions I have two endpoints delivering a list of Projects and one to get individual Projects like this api/project (gets all projects) api/project/1 (gets project with id 1). I'll try to sync these items by doing upserts.
Project creation might be a possibly long running procedure or it might be done on a bad connection, so the idea to create a new project is to just insert it into the cache, display it to the user with a fake id (negative number) send the data to the server and let it return the actual (DB generated) ID.
it currently works like this:
I now have several questions:
Beta Was this translation helpful? Give feedback.
All reactions