Remove unused global photos count

This commit is contained in:
2022-05-30 22:07:20 +02:00
parent 1126c1f76c
commit d87ec1835a

View File

@@ -137,13 +137,6 @@
) { ) {
count { id } count { id }
} }
countTotalPhotosByLocation: photo_aggregated (
groupBy: "location",
filter: { status: { _eq: "published" }},
) {
group
count { id }
}
countLocations: location_aggregated ( countLocations: location_aggregated (
filter: { status: { _eq: "published" }}, filter: { status: { _eq: "published" }},
) { ) {
@@ -156,32 +149,8 @@
`) `)
const { data } = res const { data } = res
// Filter continents with linked countries
const filteredContinents = data.continents.filter((cont: any) => cont.countries.length) const filteredContinents = data.continents.filter((cont: any) => cont.countries.length)
/**
* For each photos count, find the country and add the sum to it
*/
// Add count key
data.countries.forEach((country: any) => country.count = 0)
// Loop through totals by location
data.countTotalPhotosByLocation.forEach(({ group, count }: { group: { location: number }, count: { id: number }}) => {
const locationId = group.location
const photosCount = Number(count.id)
const countryIndex = data.countries.findIndex((country: any) => {
// Find the location of a country
return country.locations.find((location: any) => {
// Match the count location ID to the country location ID
return Number(location.id) === locationId
})
})
// Increment the count value found above
data.countries[countryIndex].count += photosCount
})
return { return {
props: { props: {
data: { data: {