Thank you for reading.
Well, this was classic MVC project that used ORM that was based on Active record pattern. Usually ORM would make one query for main entity, and one query for related entity (just like GraphQL), and once it have all data it would connect related entities in memory.
But this ORM in this particular case did not do that. Relation between those two entities was polymorphic relationships. And, in that case, ORM would fetch list of main entities, iterate over them, and for each entry do additional query.
This is waste of resources for sure, but it would not be as big of a problem if paging was done on the server side.