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:
@@ -12,6 +12,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 useCatalogHubs() {
|
||||
const { t } = useI18n()
|
||||
@@ -69,9 +70,21 @@ export function useCatalogHubs() {
|
||||
// Default: fetch all hubs with filters
|
||||
const transportType = selectedFilter.value === 'all' ? null : selectedFilter.value
|
||||
const country = selectedCountry.value === 'all' ? null : selectedCountry.value
|
||||
const bounds = filterBounds.value
|
||||
const data = await execute(
|
||||
GetNodesDocument,
|
||||
{ limit: PAGE_SIZE, offset, transportType, country },
|
||||
{
|
||||
limit: PAGE_SIZE,
|
||||
offset,
|
||||
transportType,
|
||||
country,
|
||||
...(bounds && {
|
||||
west: bounds.west,
|
||||
south: bounds.south,
|
||||
east: bounds.east,
|
||||
north: bounds.north
|
||||
})
|
||||
},
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
@@ -111,12 +124,20 @@ export function useCatalogHubs() {
|
||||
})
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize data if not already loaded
|
||||
const init = async () => {
|
||||
if (!isInitialized.value && items.value.length === 0) {
|
||||
@@ -142,6 +163,7 @@ export function useCatalogHubs() {
|
||||
fetchPage,
|
||||
loadMore,
|
||||
init,
|
||||
setProductFilter
|
||||
setProductFilter,
|
||||
setBoundsFilter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user