Skip to content

Commit

Permalink
CHORE: fixed PreviewTable caching behavior on landing page + initial …
Browse files Browse the repository at this point in the history
…page load for /blocks and /transactions
  • Loading branch information
ejmg committed Aug 5, 2024
1 parent 5e4467e commit 3c1866a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/blocks/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Page = () => {
queryClient.prefetchQuery({
queryFn: () => getBlocks({ endpoint, pageIndex: 0}),
queryKey: [queryName, defaultQueryOptions.pageIndex],
staleTime: 0,
meta: {
errorMessage,
},
Expand Down
4 changes: 4 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,23 @@ export default function Home() {
queryClient.prefetchQuery({
queryFn: () => getTransactions({ endpoint: transactionEndpoint, pageIndex: 0 }),
queryKey: [transactionsQuery],
staleTime: 0,
meta: {
errorMessage,
},
}),
queryClient.prefetchQuery({
queryFn: () => getBlocks({ endpoint: blocksEndpoint, pageIndex: 0 }),
queryKey: [blocksQuery],
staleTime: 0,
meta: {
errorMessage,
},
}),
]);

// console.log(queryClient)

return (
<div className="flex flex-wrap gap-3 items-center justify-between py-5">
<LandingCard
Expand Down
1 change: 1 addition & 0 deletions src/app/transactions/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Page = () => {
queryClient.prefetchQuery({
queryFn: () => getTransactions({ endpoint, pageIndex: 0}),
queryKey: [queryName, defaultQueryOptions.pageIndex],
staleTime: 0,
meta: {
errorMessage,
},
Expand Down
2 changes: 2 additions & 0 deletions src/components/PreviewTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export function PreviewTable ({
} = useSuspenseQuery({
queryKey: [queryName],
queryFn: () => getFn({ endpoint, pageIndex }),
// refresh preview data every 15 seconds
refetchInterval: 15 * 1000,
meta: {
errorMessage,
},
Expand Down
3 changes: 3 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const makeQueryClient = () => {
queries: {
// Direct suggestion by tanstack, to prevent over-eager refetching from the client.
staleTime: 60 * 1000,
// TODO: configure gcTime to take advantage of queries that never update, ie /block/ht and /transaction/hash. These can be set to Infinite, basically.
// not fine-tuning now because I don't want to accidentally break the other queries without further testing. Caching has already caused enough silly bugs.
gcTime: 5 * 60 * 1000,
},
dehydrate: {
// only successful and pending Queries are included per defaults
Expand Down

0 comments on commit 3c1866a

Please sign in to comment.