From be097413a71450f12d69784f4c66ecbcc1cff82a Mon Sep 17 00:00:00 2001 From: Amogh Bharadwaj Date: Fri, 12 Jan 2024 01:48:01 +0530 Subject: [PATCH] UI: Fix caching (#1058) Refreshing in the slot page was not updating the slot table data since we aren't disabling caching there like we are in the mirrors edit page. Same goes for mirror errors page. Also just adds `cache:no-store` in a few other fetches for safety --- ui/app/mirrors/create/handlers.ts | 4 ++++ ui/app/mirrors/create/page.tsx | 2 +- ui/app/mirrors/errors/[mirrorName]/page.tsx | 1 + ui/app/peers/[peerName]/page.tsx | 8 ++++++-- ui/app/peers/create/[peerType]/handlers.ts | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ui/app/mirrors/create/handlers.ts b/ui/app/mirrors/create/handlers.ts index bf6bfcc8b5..50d9a3903a 100644 --- a/ui/app/mirrors/create/handlers.ts +++ b/ui/app/mirrors/create/handlers.ts @@ -262,6 +262,7 @@ export const fetchSchemas = async (peerName: string) => { body: JSON.stringify({ peerName, }), + cache: 'no-store', }).then((res) => res.json()); return schemasRes.schemas; }; @@ -278,6 +279,7 @@ export const fetchTables = async ( peerName, schemaName, }), + cache: 'no-store', }).then((res) => res.json()); let tables: TableMapRow[] = []; @@ -320,6 +322,7 @@ export const fetchColumns = async ( schemaName, tableName, }), + cache: 'no-store', }).then((res) => res.json()); setLoading(false); return columnsRes.columns; @@ -332,6 +335,7 @@ export const fetchAllTables = async (peerName: string) => { body: JSON.stringify({ peerName, }), + cache: 'no-store', }).then((res) => res.json()); return tablesRes.tables; }; diff --git a/ui/app/mirrors/create/page.tsx b/ui/app/mirrors/create/page.tsx index 6b6e23f499..bd6fb1fd8d 100644 --- a/ui/app/mirrors/create/page.tsx +++ b/ui/app/mirrors/create/page.tsx @@ -69,7 +69,7 @@ export default function CreateMirrors() { BETWEEN {{.start}} AND {{.end}}`); useEffect(() => { - fetch('/api/peers') + fetch('/api/peers', { cache: 'no-store' }) .then((res) => res.json()) .then((res) => { setPeers(res); diff --git a/ui/app/mirrors/errors/[mirrorName]/page.tsx b/ui/app/mirrors/errors/[mirrorName]/page.tsx index fb214f8361..d0148b6b7b 100644 --- a/ui/app/mirrors/errors/[mirrorName]/page.tsx +++ b/ui/app/mirrors/errors/[mirrorName]/page.tsx @@ -50,6 +50,7 @@ export default function MirrorError() { headers: { 'Content-Type': 'application/json', }, + cache: 'no-store', body: JSON.stringify(req), }); const data: MirrorLogsResponse = await response.json(); diff --git a/ui/app/peers/[peerName]/page.tsx b/ui/app/peers/[peerName]/page.tsx index 45ddb41e61..61573365d5 100644 --- a/ui/app/peers/[peerName]/page.tsx +++ b/ui/app/peers/[peerName]/page.tsx @@ -15,7 +15,10 @@ const PeerData = async ({ params: { peerName } }: DataConfigProps) => { const flowServiceAddr = GetFlowHttpAddressFromEnv(); const peerSlots: PeerSlotResponse = await fetch( - `${flowServiceAddr}/v1/peers/slots/${peerName}` + `${flowServiceAddr}/v1/peers/slots/${peerName}`, + { + cache: 'no-store', + } ).then((res) => res.json()); const slotArray = peerSlots.slotData; @@ -42,7 +45,8 @@ const PeerData = async ({ params: { peerName } }: DataConfigProps) => { const flowServiceAddr = GetFlowHttpAddressFromEnv(); const peerStats: PeerStatResponse = await fetch( - `${flowServiceAddr}/v1/peers/stats/${peerName}` + `${flowServiceAddr}/v1/peers/stats/${peerName}`, + { cache: 'no-store' } ).then((res) => res.json()); return peerStats.statData; diff --git a/ui/app/peers/create/[peerType]/handlers.ts b/ui/app/peers/create/[peerType]/handlers.ts index 4b2858ae4e..2eeb657bbf 100644 --- a/ui/app/peers/create/[peerType]/handlers.ts +++ b/ui/app/peers/create/[peerType]/handlers.ts @@ -81,6 +81,7 @@ export const handleValidate = async ( config, mode: 'validate', }), + cache: 'no-store', }).then((res) => res.json()); if (!valid.valid) { setMessage({ ok: false, msg: valid.message }); @@ -118,6 +119,7 @@ export const handleCreate = async ( config, mode: 'create', }), + cache: 'no-store', }).then((res) => res.json()); if (!createdPeer.created) { setMessage({ ok: false, msg: createdPeer.message });