Speed up cycles thru JS generated by AI

Hello,

Bubble.io has issues with the speed of calculation for loops with a large number of repetitions. I decided to show you a solution using JS. I do not claim that my solution will specifically solve your problem, I am just demonstrating my experience. How to proceed with this information is up to you.

I am not a master of words, I immediately apologize for the quality of the content. I welcome any criticism of the article.

In addition, I will show how to use the Tollbox plugin, specifically its “javascript to Bubble” element and the “Run Javascript” action.

I won’t go into the specific requirements of my task. Instead, I’ll try to describe it in a way that makes it easy to apply what’s described below to other cases.

Also, I don’t claim that the method chosen to solve the task is the best one. I’m comparing the speed of getting the same result using available methods.

Task description:
There is a list of tasks, and we know the number of hours required to complete each one. By specifying the start and end dates of the entire list, we need to calculate the deadline for each specific task.

Given:
start date
end date
hours array
holidays array

Find:
deadline array

As references, I was provided with a table:

Before calculating the deadlines, it’s necessary to calculate the number of days required for each task. To do this, we’ll immediately find the “k” coefficient of the number of hours per day that the hours need to be divided into to get the number of days:

image
image
image

Solution with native bubble tools:

Next, we pass the hours array and start date to the back end loop:


In the loop, in turn, starting from the first job (the first value of the days array), we start another cycle:

In the second cycle, using the iteration method, starting from start date, we add one day each and check whether the new day is a weekend (you can also check whether it is not contained in the holidays array):

If the conditions are met, then we subtract 1 from the first number from the days array and restart the cycle, otherwise we simply restart the cycle. We do this until the number becomes = 0.


When the number of days has become = 0, we write the resulting date as the deadline for the first work and run the next iteration, where we will work with the next number from the days array, adding all the previous ones to it, the starting date remains the same.


Thus, we get a cycle within a cycle. The speed of calculating deadlines for 10 works with a total duration of a year, I detected on the timer. It took a little less than 5 minutes for the backend of the bubble.io While the JS script has only about 8 seconds, and this is taking into account the cycle that, after executing the script, made entries to the table for some time. In fact, the script is executed almost instantly. left column bubble, right column JS

Solution using JS:

I think there is no need to add anything here, you can see everything in the screenshots. By the way, there is a more accurate way to count the working days between two dates, this can also be done using JS (write in the comments if interested).





Yes, at the end just pictures, if you have any questions do not hesitate to ask in the comments. Here is my linkedin: https://www.linkedin.com/in/artyomka/

5 Likes