bhakta_jam
bhakta_jam
DTDrizzle Team
Created by bhakta_jam on 9/22/2024 in #help
Only run some queries if conditions changed.
I have these two queries that run one after another const facilitiesQuery = baseQuery.where(and(...conditions)); const dynamicQuery = facilitiesQuery.$dynamic(); const data = await withPagination(dynamicQuery, page, limit); const totalQuery = db.select({ total: count() }).from(facilities); const totalQueryConditions = totalQuery.where(and(...conditions)).$dynamic(); const total = await totalQueryConditions; first one gets paginated results and the second one is getting the total number of rows that match the condition (all the results, not paginated) My question, is there a way for me to skip the total count if no conditions have changed and retrurn the already calculated value. I was looking at the new cache() function by react, but would love to know the best approach to handle this? Thank you.
4 replies