Not sure how to split API calls to optimize for optimistic updates
My web app has tasks of 2 types -
1. projects tasks (which are part of a project, and in the project part of a stage)
2. individual tasks (which are standalone)
I have a route where I can see 'My Tasks' from both of these sources. Right now I have an api which gives all my tasks from both these sources. When I click on a task, it opens a panel where I have another api which gives me that task with all its attributes.
Now, when I go to change the status of the task, I want 2 things to happen -
1. The panel should update optimistically
2. The task list should re-arrange optimistically
For 1, I need to update ["tasks" , _id] in the cache, but for 2 I need to update ["tasks", "all"].
Question 1 - Does it sound fine so far? 2 optimistic updates for the same task?
Now the issue arises when I think about another view, say the project view. In that view tasks are stored by stage ["tasks", "project", projectId, "stage", stageId]. When I make an optimistic update, I need to make it for the stage tasks above and for the panel (["tasks"_id"]) as I did for the My Tasks route. I need to now handle 2 types of optimistic updates based on the view I am in for the same task update.
Question 2 - Is this approach fine? Doesn't feel like the most clean approach so I am curious for what the recommended apporach is.
0 Replies