From ab6227b7e6d3754283d00e55ccc0fb40a7c94744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Tue, 12 Oct 2021 00:06:55 +0200 Subject: [PATCH] Use aggregated data from Directus to count photos on Location page --- src/routes/[country]/[location]/index.svelte | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/routes/[country]/[location]/index.svelte b/src/routes/[country]/[location]/index.svelte index 98d894e..846adb7 100644 --- a/src/routes/[country]/[location]/index.svelte +++ b/src/routes/[country]/[location]/index.svelte @@ -210,6 +210,7 @@ }, limit: ${import.meta.env.VITE_LIST_AMOUNT}, ) { + id name slug description @@ -243,24 +244,21 @@ date_created } - total_published: photo ( - filter: { - status: { _eq: "published" }, - location: { slug: { _eq: "${location}" }} - } - ) { - id + total_published: photo_aggregated (groupBy: "location") { + group + count { id } } } `) const { data } = res + const locationPhotosCount = data.total_published.find(({ group }: any) => group.id === data.location.id) return { props: { data: data.location[0], photos: data.photos, - totalPhotos: data.total_published.length, + totalPhotos: locationPhotosCount.count.id, lastUpdated: data.photos[0].date_created, } }