Optimize catalog loading: backend bounds filtering + early returns
All checks were successful
Build Docker Image / build (push) Successful in 4m12s
All checks were successful
Build Docker Image / build (push) Successful in 4m12s
- Add bounds (west/south/east/north) parameters to GetNodes query - Add setBoundsFilter to useCatalogHubs, useCatalogSuppliers, useCatalogProducts - Replace client-side bounds filtering with backend query - Add early return to setProductFilter to avoid redundant fetches - Watch filterByBounds to trigger backend refetch when checkbox changes
This commit is contained in:
@@ -10,6 +10,7 @@ const isLoading = ref(false)
|
||||
const isLoadingMore = ref(false)
|
||||
const isInitialized = ref(false)
|
||||
const filterProductUuid = ref<string | null>(null)
|
||||
const filterBounds = ref<{ west: number; south: number; east: number; north: number } | null>(null)
|
||||
|
||||
export function useCatalogSuppliers() {
|
||||
const { execute } = useGraphQL()
|
||||
@@ -52,15 +53,31 @@ export function useCatalogSuppliers() {
|
||||
}
|
||||
|
||||
// Default: fetch all suppliers
|
||||
// If bounds filter is active, fetch more and filter client-side
|
||||
// TODO: Add bounds support to exchange backend for proper server-side filtering
|
||||
const bounds = filterBounds.value
|
||||
const fetchLimit = bounds ? 500 : PAGE_SIZE
|
||||
const data = await execute(
|
||||
GetSupplierProfilesDocument,
|
||||
{ limit: PAGE_SIZE, offset },
|
||||
{ limit: fetchLimit, offset: bounds ? 0 : offset },
|
||||
'public',
|
||||
'exchange'
|
||||
)
|
||||
const next = data?.getSupplierProfiles || []
|
||||
let next = data?.getSupplierProfiles || []
|
||||
|
||||
// Client-side bounds filtering (until exchange backend supports it)
|
||||
if (bounds) {
|
||||
next = next.filter((s: any) => {
|
||||
if (!s.latitude || !s.longitude) return false
|
||||
const lat = Number(s.latitude)
|
||||
const lng = Number(s.longitude)
|
||||
return lat >= bounds.south && lat <= bounds.north
|
||||
&& lng >= bounds.west && lng <= bounds.east
|
||||
})
|
||||
}
|
||||
|
||||
items.value = replace ? next : items.value.concat(next)
|
||||
total.value = data?.getSupplierProfilesCount ?? total.value
|
||||
total.value = bounds ? next.length : (data?.getSupplierProfilesCount ?? total.value)
|
||||
isInitialized.value = true
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
@@ -85,12 +102,20 @@ export function useCatalogSuppliers() {
|
||||
}
|
||||
|
||||
const setProductFilter = (uuid: string | null) => {
|
||||
if (filterProductUuid.value === uuid) return // Early return if unchanged
|
||||
filterProductUuid.value = uuid
|
||||
if (isInitialized.value) {
|
||||
fetchPage(0, true)
|
||||
}
|
||||
}
|
||||
|
||||
const setBoundsFilter = (bounds: { west: number; south: number; east: number; north: number } | null) => {
|
||||
filterBounds.value = bounds
|
||||
if (isInitialized.value) {
|
||||
fetchPage(0, true)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
items,
|
||||
total,
|
||||
@@ -101,6 +126,7 @@ export function useCatalogSuppliers() {
|
||||
fetchPage,
|
||||
loadMore,
|
||||
init,
|
||||
setProductFilter
|
||||
setProductFilter,
|
||||
setBoundsFilter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user