Could someone advise me how to change my current function so that looping through every item in the repeater would be done slowly? I think this could be fixed by an async function but I have only managed to change the name of it :). My current problem is that this function very poorly updates buttons in a repeater when it is called. Usually only half of the buttons are affected and mostly at the beginning of the repeater, which results in showing incorrect information in the repeater when a date is changed. There are about 20 items in the repeater, thus 40 buttons need to be updated when this function is called. Let me know if you need any additional context to suggest a solution for this function.
The way you have this set up, I think you may be running 80 queries when the function is called. You probably wanna use onItemReady instead of forEach and probably use .limit() in your queries as well.
Thanks, I have set the limit to 1 and I have changed it to onItemReady and the reliability might have increased but still it shows quite a lot of incorrect data. Is it possible to introduce some variables that would check that an item in the repeater is updated before continuing with a next item?
Well when using async functions, you usually have some intensive process you need to complete first. In this case it’s probably your queries since you have multiple operations going on inside. So you could declare each query as its own function, either within the page or in public/backend and then await the first before calling the second.
Hey James, what are you trying to do? Having two queries inside of the onItemReady() function is definitely not a good idea - very slow. Also, where are you setting the .data property of the Repeater?
Hi Yisrael,
The repeater displays about 20 available slots (dataset ‘Availability’) in a week with “Book one-off” and “Book weekly“ buttons. Each item in the repeater has a number (itemData.no) which is the time in milliseconds from the start of the week to the start of a lesson. There is another dataset ‘Lessons’ that contains actually booked lessons (currently about 400, and over time this number should increase, thus it would be great to have a properly working code so that I would not need to delete previous lessons to increase the reliability of updating the repeater).
When curtain buttons are clicked, date of each item in the repeater is updated accordingly to show a slot in a particular week (text of the date is changed) and the two booking buttons are either hidden or show by using information from “Lessons“ dataset.
“Book one-off” is shown if there is no lesson booked with the same number in that week.
“Book weekly“ is shown if there are no lessons booked with the same number in the future.
To access data of an item in the repeater I use itemData.no, I am not sure what you mean by .data?
Do you think splitting 2 loops of queries into separate functions would help? They would most likely still be run at the same time, thus I am not sure if this would prevent them from running at the same time.
Do you have any other suggestions how to improve this?