Open-Assistant
Open-Assistant copied to clipboard
Task page makes several new_task requests during loading
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.
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.
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.
It seems that useGenericTaskAPI doesn't fix fully the problem.
In production build page makes 2 requests on first load / reload.
I have added a temporary solution in #550 diff
We should test this thoroughly though, we don't want us to ddos our backend.
Not the case anymore.