Optimize Data Handling

about below url , there is a microflow at the left side on section Commits Inside a Loop , if we replace create activity with change activity and commit inside the loop (as a new microflow ), then we need to apply a best practise on the it, is it just we have to remove a commit activity outside the microflow  ? or there is some thing else we should do , like create any list ?   Mendix Academy - 3.4 Data Handling Optimizations
1 answers

Hello Deena,


It is a bad practice to commit inside the loop, because this will trigger a commit to the database on every iteration. However if you commit a list, everything is commit in a single batch.


To be able to commit a list, you first have to have a list. There are probably 2 main scenarios:

  1. You're iterating over an existing list of objects, in a loop applying some changes to the objects.
  2. You're iterating over an existing list of objects, in a loop creating new objects, maybe associated to the iterator.

In the first scenario, you would make changes inside the loop and commit the list of objects ouside of the loop.

In the second scenario, you would have to create a new list prior to looping. Then inside the loop you create the object followed by adding it to the newly created list. After the loop you can commit the list at once instead of committing every single object inside the loop.


Does this answer your question?