is there a more optimal solution than iterating over each element of the list?

0
I would like to go through the list and check how many values in it, are equal to one of the enumeration values, is there any more optimal way to do this than iterate through the list and compare each of the 7 values? And if I create a Counter object, with 7 values, how to extract the highest integer value from this object?
asked
2 answers
1

Hi Adam,

 

1. Retrieve the whole list from database.
2. For each enumeration value, add a Filter list operation to take records that match the value.
3. Count the filtered lists (7 lists in your case).
4. Use max function to take the highest count https://docs.mendix.com/refguide/mathematical-function-calls/#2-max

 

This approach only requires one database retrieval. Hope this helps.

answered
2

Hi, I know your question has been answered already and there is nothing wrong with this approach. But do keep in mind that if you are working with large data tables you can run into problems by retrieving the full list. Maybe consider this approach.

  1. Do a from database retrieve
  2. Constrain your data with Xpath.
  3. Do a count action directly after the retrieve and don't use that same list again futher in the Microflow. This will allow mendix to do an optimized retrieve and thus only doing a count on the DB and not pulling the actual data into your application.

Please view the images below as examples. It may look like overcomplicating things. But this method works great for large data sets if you really do have to count and display totals relating to your data.

 

 

answered