OutSystems Performance Best Practices: Minimize the Number of Executed Queries — a Practical Example
I will never forget that time when I was starting out as an OutSystems developer. As the first few people who started using the platform in Malaysia, it was really a pain as our team is not aware on how to actually use it properly. There is not much support that we received and some help arrived only in the middle of the project. Well, we learned the lesson. (I’ll probably write another one about it later on).
One of those things that I really messed up is related to performance. Since we are dealing with small data during development, it’s not that obvious that it’s wrong. The output is correct so I guess we did it right? :D
Here it is.
Let’s say we have 2 entities, Order (normal) and OrderType (static).
Now, in one of the actions, we needed to loop inside the open orders and check some conditions. Depending on which condition it matches, we will assign the Discount and only get the Discount in the GetOrderTypes if a specific condition is met.
But the moment we have a bunch of orders, say hundreds of thousands of orders, the website gets slower. Obviously, right? You might think, “You should just join Order and OrderTypes!”. Yes, that is possible if the logic is as simple as this. Most of the things that we have done are much more complicated and this is just a representation to simplify things.
At this point, we are not aware on how to utilize the power of List Actions. If you are not familiar, these are System actions that can filter, get index or sort a list.
In the previous action logic, the site gets slower because for each of the loop, we are having another trip to the database. We are basically querying the OrderTypes for each of the Orders.
To fix this, instead of having the aggregate inside the loop, we put it outside and use the ListFilter.
Now we only have 2 round trips to the database instead of hundreds of thousands! I do wish I could go back time and fix all of those messy things I have done in my very first OutSystems project.
There are a lot more of these Performance Best Practices. I suggest you go to this link: OutSystems Performance Best Practices and make sure you to remember them and apply them as much as possible.
Happy low-coding!