From d264f14b13efc6850e9b38401b7c281ad4512808 Mon Sep 17 00:00:00 2001 From: ejmg Date: Wed, 11 Sep 2024 14:46:55 -0500 Subject: [PATCH 1/2] cache config tweaks + fetch params --- apps/web/src/components/BlocksTable/getBlocks.ts | 5 +++-- apps/web/src/components/PreviewTable/index.tsx | 5 +++-- apps/web/src/components/TransactionsTable/getTransactions.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/BlocksTable/getBlocks.ts b/apps/web/src/components/BlocksTable/getBlocks.ts index 83c15d0..85ce140 100644 --- a/apps/web/src/components/BlocksTable/getBlocks.ts +++ b/apps/web/src/components/BlocksTable/getBlocks.ts @@ -1,10 +1,11 @@ import { getBaseURL } from "@/lib/utils"; import { BlocksTableQuery } from "@/lib/validators/table"; -export async function getBlocks ({ endpoint, pageIndex } : ({ endpoint: string, pageIndex: number })) { +export async function getBlocks ({ endpoint, pageIndex, cached = true } : ({ endpoint: string, pageIndex: number, cached?: boolean })) { const baseUrl = getBaseURL(); console.log(`Fetching: GET ${baseUrl}/${endpoint}/?page=${pageIndex}`); - const res = await fetch(`${baseUrl}/${endpoint}?page=${pageIndex}`, { method: "GET" }); + + const res = await fetch(`${baseUrl}/${endpoint}?page=${pageIndex}`, { method: "GET", cache: ( cached ? "default" : "no-store") }); const json = await res.json(); console.log("Fetched result:", json); diff --git a/apps/web/src/components/PreviewTable/index.tsx b/apps/web/src/components/PreviewTable/index.tsx index 11da1f9..de71098 100644 --- a/apps/web/src/components/PreviewTable/index.tsx +++ b/apps/web/src/components/PreviewTable/index.tsx @@ -52,9 +52,10 @@ export function PreviewTable ({ } } = useSuspenseQuery({ queryKey: [queryName, pageIndex], - queryFn: () => getFn({ endpoint, pageIndex }), + queryFn: () => getFn({ endpoint, pageIndex, cached: false }), + // staleTime: 0, // refresh preview data every 15 seconds - refetchInterval: 15 * 1000, + refetchInterval: 10 * 1000, meta: { errorMessage, }, diff --git a/apps/web/src/components/TransactionsTable/getTransactions.ts b/apps/web/src/components/TransactionsTable/getTransactions.ts index 7e3fba1..f197401 100644 --- a/apps/web/src/components/TransactionsTable/getTransactions.ts +++ b/apps/web/src/components/TransactionsTable/getTransactions.ts @@ -1,10 +1,10 @@ import { getBaseURL } from "@/lib/utils"; import { TransactionsTableData } from "@/lib/validators/table"; -export async function getTransactions({ endpoint, pageIndex } : { endpoint: string, pageIndex: number}) { +export async function getTransactions({ endpoint, pageIndex, cached = true } : { endpoint: string, pageIndex: number, cached?: boolean}) { const baseUrl = getBaseURL(); console.log(`Fetching: POST ${baseUrl}/${endpoint}?page=${pageIndex}`); - const res = await fetch(`${baseUrl}/${endpoint}?page=${pageIndex}`, { method: "GET" }); + const res = await fetch(`${baseUrl}/${endpoint}?page=${pageIndex}`, { method: "GET", cache: ( cached ? "default" : "no-store") }); const json = await res.json(); console.log("Fetched Result:", json); const result = TransactionsTableData.safeParse(json); From 5687443ad4adae4ea72f015fa0457756e2588cbb Mon Sep 17 00:00:00 2001 From: ejmg Date: Wed, 11 Sep 2024 18:10:00 -0500 Subject: [PATCH 2/2] disable fetch's cache on landing index --- apps/web/src/app/(index)/page.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/app/(index)/page.tsx b/apps/web/src/app/(index)/page.tsx index 5f16265..d7722a4 100644 --- a/apps/web/src/app/(index)/page.tsx +++ b/apps/web/src/app/(index)/page.tsx @@ -55,7 +55,7 @@ export default function Home() { Promise.all([ queryClient.prefetchQuery({ - queryFn: () => getTransactions({ endpoint: transactionEndpoint, pageIndex: 0 }), + queryFn: () => getTransactions({ endpoint: transactionEndpoint, pageIndex: 0, cached: false }), queryKey: [transactionsQuery, 0], staleTime: 0, meta: { @@ -63,7 +63,7 @@ export default function Home() { }, }), queryClient.prefetchQuery({ - queryFn: () => getBlocks({ endpoint: blocksEndpoint, pageIndex: 0 }), + queryFn: () => getBlocks({ endpoint: blocksEndpoint, pageIndex: 0, cached: false }), queryKey: [blocksQuery, 0], staleTime: 0, meta: {