export async function getFilteredVideos( limit,
filterGrade,
filterCategory,
search,
sort,
type = "Lesson Video",
subCategory
) {
console.time("videos fetch");
let query = `*[_type == "video"]{${videoFields}}`;
query += `[type.name == "${type}"]`;
if (filterGrade && filterGrade !== "All Grades") {
query += `[ "${filterGrade}" in grade[].label ]`;
}
if (filterCategory && filterCategory !== "All Categories") {
query += `[ "${filterCategory}" in category[].title ]`;
}
if (subCategory && subCategory !== "All Subtopic") {
query += `[subCategory.title match "${subCategory}"]`;
}
if (search && search !== "All") {
query += `[name match "${search}*"]`;
}
if (sort && sort === "longest") {
query += `| order(duration desc)`;
}
if (sort && sort === "shortest") {
query += `| order(duration asc)`;
}
if (sort && sort === "relevance") {
query += `| order(type.name desc)`;
}
query += `${limit}`;
const results = await client.fetch(query);
console.timeEnd("videos fetch");
return results;
}
anyone who can help my make this query faster
Jun 19, 2023, 1:27 PM