Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid busy fetching operations but rely on events websocket #500

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pages/instances/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import React, { FC, useEffect, useState } from "react";
import { LxdEvent } from "types/event";
import { useEventQueue } from "context/eventQueue";
import { useAuth } from "context/auth";
import { useQueryClient } from "@tanstack/react-query";
import { queryKeys } from "util/queryKeys";

const Events: FC = () => {
const { isAuthenticated } = useAuth();
const eventQueue = useEventQueue();
const queryClient = useQueryClient();
const [eventWs, setEventWs] = useState<WebSocket | null>(null);

const handleEvent = (event: LxdEvent) => {
Expand Down Expand Up @@ -40,6 +43,11 @@ const Events: FC = () => {
return;
}
const event = JSON.parse(message.data) as LxdEvent;
if (event.type === "operation") {
void queryClient.invalidateQueries({
queryKey: [queryKeys.operations, event.project],
});
}
setTimeout(() => handleEvent(event), 1000); // handle with delay to allow operations to vanish
};
};
Expand Down
1 change: 0 additions & 1 deletion src/pages/instances/InstanceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const InstanceList: FC = () => {
const { data: operationList } = useQuery({
queryKey: [queryKeys.operations, project],
queryFn: () => fetchOperations(project),
refetchInterval: 1000,
});

if (error) {
Expand Down
Loading