Skip to content

Commit

Permalink
fix: set 0 default cache and stale time
Browse files Browse the repository at this point in the history
  • Loading branch information
seoulyego committed Oct 31, 2024
1 parent 680cdca commit 86116f7
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/components/Comment/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export default function Comment({ userData }) {
isError,
error,
isLoading,
} = useKyQuery(`products/${id}/comments`, undefined, { staleTime: 0 })
} = useKyQuery(`products/${id}/comments`, undefined, {
gcTime: 0,
staleTime: 0,
})

if (isError) return <div>{error}</div>
if (isLoading) return <div>loading</div>
Expand Down
5 changes: 4 additions & 1 deletion src/components/UserProfile/UserFollowButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const useCheckFollow = (id) => {
data: following,
isLoading,
isError,
} = useKyQuery(`me/following/${id}`, ['me/following', id])
} = useKyQuery(`me/following/${id}`, ['me/following', id], {
gcTime: 300000,
staleTime: 300000,
})

if (isLoading || isError) return undefined

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useFetchContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const useFetchContent = (id) => {
const [currentPage, setCurrentPage] = useState(initialPageData)
const url = parseQueryParams(`members/${id}/products`, currentPage)
const { data: productList } = useKyQuery(url, undefined, {
gcTime: 0,
staleTime: 0,
enabled: !!id,
})
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useKyQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const useKyQuery = (uri, queryKey = [uri], options = null) => {
return useQuery({
queryKey,
queryFn: () => kyInstance.get(uri).json(),
gcTime: 300000,
staleTime: 300000,
gcTime: 0,
staleTime: 0,
retry: false,
...options,
})
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useNotificationFetch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const useNotificationFetch = () => {
data: notifications,
isError,
isPending,
} = useKyQuery('notifications', undefined, { staleTime: 60000 })
} = useKyQuery('notifications', undefined, {
gcTime: 60000,
staleTime: 60000,
})

if (isPending || isError)
return {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useProductData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function useProductData() {
})

const { isLoading, data, isError } = useKyQuery(uri, undefined, {
gcTime: 0,
staleTime: 0,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import CategorySelectList from './CategorySelectList'
import TagSelectForm from './TagSelectForm'

export default function CategorySubmitForm() {
const { data: categories } = useKyQuery('categories/hierarchy')
const { data: categories } = useKyQuery('categories/hierarchy', {
gcTime: 300000,
staleTime: 300000,
})

return (
<>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/SubmitPage/components/InfoSubmit/InfoSubmit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import RatingInput from './RatingInput'
import NumberInputForm from './NumberInputForm'

export default function InfoSubmitForm() {
const { data: currencies, isLoading } = useKyQuery('currencies')
const { data: currencies, isLoading } = useKyQuery('currencies', undefined, {
gcTime: 300000,
staleTime: 300000,
})

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import useKyQuery from '@hooks/useKyQuery'

const useDefaultCurrency = (setFormContents) => {
const country = useFormStore((state) => state.country)
const { data, isLoading } = useKyQuery(`currencies?country_id=${country.id}`)
const { data, isLoading } = useKyQuery(
`currencies?country_id=${country.id}`,
undefined,
{
gcTime: 300000,
staleTime: 300000,
}
)

useEffect(() => {
if (!isLoading) setFormContents({ currencyId: data.data[0].id })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import RegionSelectList from './RegionSelectList'
import AddressInputForm from './AddressInputForm'

export default function RegionSubmitPage() {
const { data: regions } = useKyQuery('regions/hierarchy')
const { data: regions } = useKyQuery('regions/hierarchy', undefined, {
gcTime: 300000,
staleTime: 300000,
})

return (
<>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/UserPage/FollowingList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ function FollowingList() {
const { data: followingList, isLoading } = useKyQuery(
'me/following',
undefined,
{ staleTime: 0 }
{
gcTime: 0,
staleTime: 0,
}
)

if (isLoading) return null
Expand Down
1 change: 1 addition & 0 deletions src/pages/UserPage/ReviewList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function ReviewList({ selectedMenu }) {
const [currentPage, setCurrentPage] = useState(initialPageData)
const url = parseQueryParams(`${selectedMenu}`, currentPage)
const { data: productList } = useKyQuery(url, undefined, {
gcTime: 0,
staleTime: 0,
})

Expand Down

0 comments on commit 86116f7

Please sign in to comment.