Hi,
I am still quite new to coding, and I have had a piece of code that queries different datasets based on a random number generated. The result will then be displayed on the page. What I have noticed is that there’s up to 3 secs delay when displaying results on the page. I am looking to speed up the display to less than 1 sec but i don’t know enough to make that happen. Can someone point a direction please?
Example of the code:
const getRandomNo = (max) =>{
return Math.floor(Math.random() * Math.floor(max));
}
let tip = getRandomNo(3)
if (tip === 0) {
queryInterests()
.then(result=>{
let items = result.items.sort(compare);
let index = getRandomNo(5);
let tipPercentage1 = items[index].percentage1;
let tipSubject = items[index].interests;
$w(‘#tipNumber’).text = ${tipPercentage1.toFixed(0)}%
;
$w(‘#tipSubject’).text = ${tipSubject.toLowerCase()} ?
;
})
}
Note 1: queryInterests() is a straight forward wix-data.query running at a backend file.
Note 2: percentage1 is generated through data hook afterQuery()