Delay on repeater loading

Hi guys,

I have setup some filters on my repeater which work with dropdowns onChange.

I have finally worked out how to ‘reset’ each one to All but when I do this, the repeater takes 3 or so secs to load the data again?? Can someone please help or is this a bug? Thanks

My page : https://pete092.wixsite.com/book-the-best/copy-of-queensland

&

Code below:

import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;

export function location_change() {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
let location = $w(‘#location’).value;
if (location === ‘All’) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
});
}
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}

export function Type_change() {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
let type = $w(‘#Type’).value;
if (type === ‘All’) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
});
}
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}

export function Guests_change(event, $w) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}

export function Rooms_change(event, $w) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}

export function Bathrooms_change(event, $w) {
wixData.query(“Properties”)
.contains(“location”, “Queensland”)
.contains(“subLocation”, $w(‘#location’).value)
.contains(“type”, $w(‘#Type’).value)
.ge(“guests”, Number($w(“#Guests”).value))
.ge(“bedrooms”, Number($w(“#Rooms”).value))
.ge(“bathrooms”, Number($w(“#Bathrooms”).value))
.find()
.then((results) => {
$w(‘#repeater2’).data = results.items;
if (results.items.length === 0) {
$w(‘#box3’).show();
} else $w(‘#box3’).hide();
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}

1 Like

Hey
There is a lot of queries that must run and execute so that might take some time. How many properties do you have in your system at the most? Do you have more than 1500? 15000? If you have fewer than 1000 I would create a cached object with the data and that would speed up your page a lot. You also run one query first and if a property is all you run that query again, that’s bad. Only run it once so moce your if location = all to the first line and then just query the data.

I would also make a single function that will do all the query stuff. If you need help with this ping here and I will see what I can come up with.

Hey Andreas thanks so much for having a look! I am in beta testing so only have 10 - 20 properties and it only happens now that I have added the ‘All’ IF code to each OnChange as you mention. Is there a way to write this better so I am not querying twice? Thank you!

Hey Andreas have u had a chance to look at this at all? I tidies up the code and loads faster but now shows my ‘no items found’ box quickly before displaying the correct results?

thank you!

Hi,
There’s a detailed example here which can be useful for you for filtering a repeater using multiple drop downs.

Good luck,
Tal.