Skip to content

Commit

Permalink
Merge pull request #66 from oxen-io/fix/cache_revalidation
Browse files Browse the repository at this point in the history
Add cache revalidation for root pages
  • Loading branch information
Aerilym authored Oct 14, 2024
2 parents c5bbfa8 + 356d2d1 commit 47726db
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
2 changes: 0 additions & 2 deletions apps/foundation/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRevalidateHandler } from '@session/sanity-cms/api/revalidate';
import { client } from '@/lib/sanity/sanity.client';
import { SANITY_SCHEMA_URL } from '@/lib/constants';

const SANITY_REVALIDATE_SECRET = process.env.SANITY_REVALIDATE_SECRET!;
Expand All @@ -9,7 +8,6 @@ if (!SANITY_REVALIDATE_SECRET) {

export const { POST } = createRevalidateHandler({
revalidateSecret: SANITY_REVALIDATE_SECRET,
client: client,
schemaUrls: {
page: SANITY_SCHEMA_URL.PAGE,
post: SANITY_SCHEMA_URL.POST,
Expand Down
12 changes: 2 additions & 10 deletions packages/sanity-cms/api/revalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import logger from '../lib/logger';
import { safeTry } from '@session/util-js/try';
import type { PageSchemaType } from '../schemas/page';
import type { PostSchemaType } from '../schemas/post';
import { getSiteSettings } from '../queries/getSiteSettings';
import type { SessionSanityClient } from '../lib/client';

type RssGeneratorConfig = {
/** The CMS content type that the generator should be run for.*/
Expand All @@ -21,7 +19,6 @@ type RssGeneratorConfig = {
type CreateRevalidateHandlerOptions = {
/** The secret used to verify the webhook request. */
revalidateSecret: string;
client: SessionSanityClient;
schemaUrls: Record<string, string>;
/** An array of RSS generator configurations. {@link RssGeneratorConfig} */
rssGenerators?: Array<RssGeneratorConfig>;
Expand Down Expand Up @@ -56,7 +53,6 @@ type CreateRevalidateHandlerOptions = {
*/
export const createRevalidateHandler = ({
revalidateSecret,
client,
schemaUrls,
rssGenerators,
}: CreateRevalidateHandlerOptions) => {
Expand Down Expand Up @@ -141,12 +137,8 @@ export const createRevalidateHandler = ({
if (!schemaUrl.endsWith('/')) {
schemaUrl = `${schemaUrl}/`;
}
const settings = await getSiteSettings({ client });
if (slug === settings?.landingPage?.slug?.current) {
revalidatePath(`${schemaUrl}`);
} else {
revalidatePath(`${schemaUrl}${slug}`);
}
revalidatePath(`${schemaUrl}`);
revalidatePath(`${schemaUrl}${slug}`);
}
}
}
Expand Down

0 comments on commit 47726db

Please sign in to comment.