-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
19,810 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 17 additions & 17 deletions
34
starters/shopify-meilisearch/app/actions/collection.actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
"use server" | ||
|
||
import { unstable_cache } from "next/cache" | ||
import { unstable_cacheTag as cacheTag, unstable_cacheLife as cacheLife } from "next/cache" | ||
import { meilisearch } from "clients/search" | ||
import { ComparisonOperators, FilterBuilder } from "lib/meilisearch/filter-builder" | ||
import { getDemoSingleCategory, isDemoMode } from "utils/demo-utils" | ||
import type { PlatformCollection } from "lib/shopify/types" | ||
import { env } from "env.mjs" | ||
|
||
export const getCollection = unstable_cache( | ||
async (slug: string) => { | ||
if (isDemoMode()) return getDemoSingleCategory(slug) | ||
export const getCollection = async (slug: string) => { | ||
"use cache" | ||
cacheTag(`collection-${slug}`) | ||
cacheLife("days") | ||
|
||
const results = await meilisearch.searchDocuments<PlatformCollection>({ | ||
indexName: env.MEILISEARCH_CATEGORIES_INDEX, | ||
options: { | ||
filter: new FilterBuilder().where("handle", ComparisonOperators.Equal, slug).build(), | ||
limit: 1, | ||
attributesToRetrieve: ["handle", "title", "seo"], | ||
}, | ||
}) | ||
if (isDemoMode()) return getDemoSingleCategory(slug) | ||
|
||
return results.hits.find(Boolean) || null | ||
}, | ||
["category-by-handle"], | ||
{ revalidate: 3600 } | ||
) | ||
const results = await meilisearch.searchDocuments<PlatformCollection>({ | ||
indexName: env.MEILISEARCH_CATEGORIES_INDEX, | ||
options: { | ||
filter: new FilterBuilder().where("handle", ComparisonOperators.Equal, slug).build(), | ||
limit: 1, | ||
attributesToRetrieve: ["handle", "title", "seo"], | ||
}, | ||
}) | ||
|
||
return results.hits.find(Boolean) || null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
"use server" | ||
|
||
import { storefrontClient } from "clients/storefrontClient" | ||
import { unstable_cache } from "next/cache" | ||
import { unstable_cacheTag as cacheTag, unstable_cacheLife as cacheLife } from "next/cache" | ||
|
||
export const getPage = unstable_cache(async (handle: string) => await storefrontClient.getPage(handle), ["page"], { revalidate: 3600 }) | ||
export const getPage = async (handle: string) => { | ||
"use cache" | ||
cacheTag(`page-${handle}`) | ||
cacheLife("days") | ||
|
||
export const getAllPages = unstable_cache(async () => await storefrontClient.getAllPages(), ["page"], { revalidate: 3600 }) | ||
return await storefrontClient.getPage(handle) | ||
} | ||
|
||
export const getAllPages = async () => { | ||
"use cache" | ||
cacheTag("all-pages") | ||
cacheLife("days") | ||
|
||
return await storefrontClient.getAllPages() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.