84 lines
2.1 KiB
TypeScript
84 lines
2.1 KiB
TypeScript
import * as siteModel from "~/models/site.model"
|
|
import { QueryClient } from "@tanstack/react-query"
|
|
import { cacheGet } from "~/lib/redis.server"
|
|
|
|
export const prefetchGetSite = async (
|
|
input: string,
|
|
queryClient: QueryClient,
|
|
) => {
|
|
const key = ["getSite", input]
|
|
await queryClient.prefetchQuery(key, async () => {
|
|
return cacheGet({
|
|
key,
|
|
getValueFun: () => siteModel.getSite(input),
|
|
})
|
|
})
|
|
}
|
|
|
|
export const fetchGetSite = async (input: string, queryClient: QueryClient) => {
|
|
const key = ["getSite", input]
|
|
return await queryClient.fetchQuery(key, async () => {
|
|
return cacheGet({
|
|
key,
|
|
getValueFun: () => siteModel.getSite(input),
|
|
})
|
|
})
|
|
}
|
|
|
|
export const prefetchGetSiteSubscriptions = async (
|
|
input: Parameters<typeof siteModel.getSiteSubscriptions>[0],
|
|
queryClient: QueryClient,
|
|
) => {
|
|
const key = ["getSiteSubscriptions", input]
|
|
await queryClient.prefetchInfiniteQuery({
|
|
queryKey: key,
|
|
queryFn: async ({ pageParam }) => {
|
|
return cacheGet({
|
|
key,
|
|
getValueFun: () => {
|
|
return siteModel.getSiteSubscriptions({
|
|
...input,
|
|
cursor: pageParam,
|
|
})
|
|
},
|
|
})
|
|
},
|
|
getNextPageParam: (lastPage) => lastPage?.cursor || undefined,
|
|
})
|
|
}
|
|
|
|
export const prefetchGetSiteToSubscriptions = async (
|
|
input: Parameters<typeof siteModel.getSiteToSubscriptions>[0],
|
|
queryClient: QueryClient,
|
|
) => {
|
|
const key = ["getSiteToSubscriptions", input]
|
|
await queryClient.prefetchInfiniteQuery({
|
|
queryKey: key,
|
|
queryFn: async ({ pageParam }) => {
|
|
return cacheGet({
|
|
key,
|
|
getValueFun: () => {
|
|
return siteModel.getSiteToSubscriptions({
|
|
...input,
|
|
cursor: pageParam,
|
|
})
|
|
},
|
|
})
|
|
},
|
|
getNextPageParam: (lastPage) => lastPage?.cursor || undefined,
|
|
})
|
|
}
|
|
|
|
export const prefetchGetSites = async (
|
|
input: number[],
|
|
queryClient: QueryClient,
|
|
) => {
|
|
const key = ["getSites", input]
|
|
await queryClient.fetchQuery(key, async () => {
|
|
return cacheGet({
|
|
key,
|
|
getValueFun: () => siteModel.getSites(input),
|
|
})
|
|
})
|
|
}
|