In this post I’m going through one of the ways to increase the performance of your flows.
In this post I will use the example of counting the number of documents in a SharePoint library.
The bad way
First of all I will start with the Get files action ( you could of course use the REST API and use the Send HTTP Request to SharePoint).
We will now find a number of documents back and we want to count these. So something like this:
That is going to be, ok if you can guarantee only a few documents in a library but as time goes on your flow will not perform for very long as more and more documents are uploaded.
You might have noticed the length function in the Expressions tab so initilizing a varbale with length(body(‘Get_Files’)) could work, but this doesn’t work as the Get files is returning JSON.
All we need to do is create an array!
The Speedy Way
The Select function is used for the creation of the array
where you can see item() simply use item()?[‘ID’] to select the ID for each item in the JSON returned by the Get files action.
Then a length(body(‘Select’)) will give you the number of items in your library:
Now just run your flow and the number of documents is returned:
Performance-wise this makes a big difference. In our first example
There we ran the following actions
- 1 trigger.
- 1 Get files
- 1 Apply to each
- 8 Increment variable
So that is 11 steps in total.
With the optimized example we only had:
- 1 trigger
- 1 get files
- 1 select
- 1 Initialize variable (and this isn’t really needed, as you could use the expression within the following steps of your overall flow)