use while loop for iterating

The other method limits the number of results without taking the
constraints into account.

Fixes GH-7883
merged branch henrikbjorn/filesystem-limit (PR #7886)

This PR was submitted for the master branch but it was merged into the 2.1 branch instead (closes #7886).

Discussion
----------

[HttpKernel][Profile] Fixes #7883

Commits
-------

0172fc1 [HttpKernel][Profile] use while loop for iterating