fix: don't cache Sanity GROQ queries

This commit is contained in:
Dorian Niemiec 2024-09-07 14:31:17 +02:00
parent 9c8a5a479d
commit 3e2bcab3ce
3 changed files with 11 additions and 3 deletions

View file

@ -28,7 +28,7 @@ async function getData(slug: string) {
_createdAt _createdAt
}[0]`; }[0]`;
const data = await client.fetch(query); const data = await client.fetch(query, {}, { cache: "no-store" });
return data; return data;
} }

View file

@ -65,7 +65,11 @@ export async function generateStaticParams() {
const cardsPerPage = 6; const cardsPerPage = 6;
const totalPostsQuery = `count(*[_type == 'blog'])`; const totalPostsQuery = `count(*[_type == 'blog'])`;
const totalPosts: number = await client.fetch(totalPostsQuery); const totalPosts: number = await client.fetch(
totalPostsQuery,
{},
{ cache: "no-store" }
);
const totalPages = Math.ceil(totalPosts / cardsPerPage); const totalPages = Math.ceil(totalPosts / cardsPerPage);

View file

@ -41,7 +41,11 @@ const BlogCards: React.FC<BlogCardInterface> = async (props) => {
_createdAt _createdAt
}[${(currentPage - 1) * cardsPerPage}...${currentPage * cardsPerPage}]`; }[${(currentPage - 1) * cardsPerPage}...${currentPage * cardsPerPage}]`;
const posts: BlogPostcard[] = await client.fetch(query); const posts: BlogPostcard[] = await client.fetch(
query,
{},
{ cache: "no-store" }
);
const totalPostsQuery = `count(*[_type == 'blog'])`; const totalPostsQuery = `count(*[_type == 'blog'])`;
const totalPosts: number = await client.fetch(totalPostsQuery); const totalPosts: number = await client.fetch(totalPostsQuery);