From 201431f6f8fe33ee8a34d6204a85136d5ac4a835 Mon Sep 17 00:00:00 2001 From: Oliveriver Date: Tue, 20 Aug 2024 23:23:34 +0100 Subject: [PATCH] Fix performance issues caused by cartesian explosion --- client/src/components/context/WorldContext.tsx | 2 +- client/src/hooks/api/useSubmitOrders.tsx | 4 ++-- server/Repositories/WorldRepository.cs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/components/context/WorldContext.tsx b/client/src/components/context/WorldContext.tsx index c7a5736..5dde52c 100644 --- a/client/src/components/context/WorldContext.tsx +++ b/client/src/components/context/WorldContext.tsx @@ -65,7 +65,7 @@ export const WorldContextProvider = ({ children }: PropsWithChildren) => { submitOrders: async (orders: Order[]) => { if (!game || !world) return; const players = game.player ? [game.player] : Object.values(Nation); - submitOrders({ gameId: game.id, players, orders }); + await submitOrders({ gameId: game.id, players, orders }); await refetchUntilUpdate(); }, isLoading: isLoading || isSubmitting || isRefetching || isWaitingForAdjudication, diff --git a/client/src/hooks/api/useSubmitOrders.tsx b/client/src/hooks/api/useSubmitOrders.tsx index 2cca5bc..1d568d0 100644 --- a/client/src/hooks/api/useSubmitOrders.tsx +++ b/client/src/hooks/api/useSubmitOrders.tsx @@ -20,11 +20,11 @@ const submitOrders = async ({ gameId, players, orders }: SubmissionRequest) => { }; const useSubmitOrders = () => { - const { mutate, ...rest } = useMutation({ + const { mutateAsync, ...rest } = useMutation({ mutationKey: ['submitOrders'], mutationFn: submitOrders, }); - return { submitOrders: mutate, ...rest }; + return { submitOrders: mutateAsync, ...rest }; }; export default useSubmitOrders; diff --git a/server/Repositories/WorldRepository.cs b/server/Repositories/WorldRepository.cs index 9c24fd6..37c59e1 100644 --- a/server/Repositories/WorldRepository.cs +++ b/server/Repositories/WorldRepository.cs @@ -21,6 +21,7 @@ public async Task GetWorld(int gameId) .Include(w => w.Boards).ThenInclude(b => b.Centres) .Include(w => w.Boards).ThenInclude(b => b.Units) .Include(w => w.Orders).ThenInclude(o => o.Unit) + .AsSplitQuery() // TODO wrap database operations in shared lock to prevent concurrency issues .FirstOrDefaultAsync(w => w.GameId == gameId) ?? throw new KeyNotFoundException("World not found");