Open-Assistant icon indicating copy to clipboard operation
Open-Assistant copied to clipboard

Task page makes several new_task requests during loading

Open Vechtomov opened this issue 2 years ago • 3 comments

Current behavior of fetching new task during page load is not deterministic. On my machine it makes 3 requests if page is loading for the first time and 2 requests on each next page open. requests It's caused by this code block

useEffect(() => {
  if (tasks.length == 0) {
    mutate();
  }
}, [tasks]);

As a solution, we can do this

const { data: task, isLoading, mutate } = useSWRImmutable("/api/new_task/initial_prompt ", fetcher, {
  revalidateOnMount: true,
});
...
if (!task) {
  return isLoading 
    ? <LoadingScreen text="Loading..." /> 
    : <Container className="p-6 text-center text-gray-800">No tasks found...</Container>;
}
const tasks = [task];

But this solution requires auto-ACK which is yet under discussion in #520. I can make a pr but it would be easier if you add me to the developers chat in discord.

Vechtomov avatar Jan 08 '23 13:01 Vechtomov

With PR #523 we've got useGenericTaskAPI hook that could solve this problem. I think we need to rewrite pages in create and evaluate routes to implement it. This should fix this.

Klotske avatar Jan 08 '23 14:01 Klotske

It seems that useGenericTaskAPI doesn't fix fully the problem. label_requests In production build page makes 2 requests on first load / reload.

Vechtomov avatar Jan 08 '23 17:01 Vechtomov

I have added a temporary solution in #550 diff

We should test this thoroughly though, we don't want us to ddos our backend.

AbdBarho avatar Jan 08 '23 18:01 AbdBarho

Not the case anymore.

AbdBarho avatar Jan 14 '23 08:01 AbdBarho