Safety of method pageManager.getPages(....)

Hi Saurabh,
Thanks for answer!
Yes, the case would be all current pages in space. I am not sure how would I streamline the process, can you elaborate on your solution a bit more please?
BTW, so you think it is better to not use the call pageManager.getPages(…)? Because for example here the accepted answer advises to use such call for retrieving all pages of given space.
Thanks for answers!