In the previous section, we ended up getting the number of files per user. We will now iterate on the previous result to create a disk-usage ranking. Since we want the disk usage, we will have to update the previous files_by_user_v3 flow so that it accumulates each file size per user id as well:
$ cat examples/search.exsimport_file("./examples/sample_data.exs")# ...disk_usage_by_user = media_set |> Flow.from_enumerable(max_demand: 1) |> Flow.partition(key: {:key, :user_id}) |> Flow.reduce(fn -> %{} end, fn %{user_id: user_id, file_size: size}, accum -> Map.update(accum, user_id, size, &(&1 + size)) end)
The previous disk_usage_by_user flow gives us the expected results, showing each user's disk usage. User 3 is clearly ...