Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 39 additions & 19 deletions src/lib/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ export async function getUser() {
}

export async function getProductsForSubcategory(subcategorySlug: string) {
"use cache: remote";
cacheTag("subcategory-products");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours
// "use cache: remote";
// cacheTag("subcategory-products");
// cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting products for subcategory ", subcategorySlug, " cache for 2 hours");

return db.query.products.findMany({
where: (products, { eq, and }) =>
Expand All @@ -61,6 +63,8 @@ export async function getCollections() {
cacheTag("collections");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting collections cache for 2 hours");

return db.query.collections.findMany({
with: {
categories: true,
Expand All @@ -70,19 +74,23 @@ export async function getCollections() {
}

export async function getProductDetails(productSlug: string) {
"use cache: remote";
cacheTag("product");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours
// "use cache: remote";;
// cacheTag("product");
// cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting product details for", productSlug, " cache for 2 hours");

return db.query.products.findFirst({
where: (products, { eq }) => eq(products.slug, productSlug),
});
}

export async function getSubcategory(subcategorySlug: string) {
"use cache: remote";
cacheTag("subcategory");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours
// "use cache: remote";;
// cacheTag("subcategory");
// cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting subcategory details for", subcategorySlug, " cache for 2 hours");

return db.query.subcategories.findFirst({
where: (subcategories, { eq }) => eq(subcategories.slug, subcategorySlug),
Expand All @@ -94,6 +102,8 @@ export async function getCategory(categorySlug: string) {
cacheTag("category");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting category details for", categorySlug, " cache for 2 hours");

return db.query.categories.findFirst({
where: (categories, { eq }) => eq(categories.slug, categorySlug),
with: {
Expand All @@ -107,10 +117,12 @@ export async function getCategory(categorySlug: string) {
}

export async function getCollectionDetails(collectionSlug: string) {
"use cache: remote";
"use cache: remote";;
cacheTag("collection");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting collection details for", collectionSlug, " cache for 2 hours");

return db.query.collections.findMany({
with: {
categories: true,
Expand All @@ -121,9 +133,11 @@ export async function getCollectionDetails(collectionSlug: string) {
}

export async function getProductCount() {
"use cache: remote";
cacheTag("total-product-count");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours
// "use cache: remote";;
// cacheTag("total-product-count");
// cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting product count cache for 2 hours");

return db.select({ count: count() }).from(products);
}
Expand All @@ -134,6 +148,8 @@ export async function getCategoryProductCount(categorySlug: string) {
cacheTag("category-product-count");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting category product count for", categorySlug, " cache for 2 hours");

return db
.select({ count: count() })
.from(categories)
Expand All @@ -147,9 +163,11 @@ export async function getCategoryProductCount(categorySlug: string) {
}

export async function getSubcategoryProductCount(subcategorySlug: string) {
"use cache: remote";
cacheTag("subcategory-product-count");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours
// "use cache: remote";;
// cacheTag("subcategory-product-count");
// cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting subcategory product count for", subcategorySlug, " cache for 2 hours");

return db
.select({ count: count() })
Expand All @@ -158,9 +176,11 @@ export async function getSubcategoryProductCount(subcategorySlug: string) {
}

export async function getSearchResults(searchTerm: string) {
"use cache: remote";
cacheTag("search-results");
cacheLife({ revalidate: 60 * 60 * 2 }); // two hours
// "use cache: remote";;
// cacheTag("search-results");
// cacheLife({ revalidate: 60 * 60 * 2 }); // two hours

console.log("Getting search results for", searchTerm, " cache for 2 hours");

let results;

Expand Down
Loading