daxus icon indicating copy to clipboard operation
daxus copied to clipboard

Resolve race condition

Open jason89521 opened this issue 1 year ago • 4 comments

There are two case of the race condition.

  • The response returned from request is after the user mutating the model.
  • Suppose useInfiniteFetch fetch a post list with id from 1 to 10, and useFetch fetch the post with id 1 later. But the response from useFetch may be in front of the response from useInfiniteFetch. In this case, we will update the model with expired response.

jason89521 avatar May 24 '23 03:05 jason89521

For the first case, we can abort the ongoing request and call the revalidate again. For the second case, I haven't figured out a solution.

jason89521 avatar May 24 '23 03:05 jason89521

It seems that we cannot resolve the second case because the model is defined from the user. However, we can pass the start time to the syncModel method such that the user can determine which data is expired.

jason89521 avatar May 24 '23 03:05 jason89521

It may be good if pagination adapter can record the timestamp. However, I need to be careful not to make the API too complex, or else it would be counterproductive.

jason89521 avatar Jun 13 '23 08:06 jason89521

In the second case, if the API for the post list is newer than the API for getting a single post, discarding the "get post" API may result in receiving incomplete data. This is because the list API usually does not return complete information. I might need to abandon this case.

jason89521 avatar Jun 13 '23 08:06 jason89521