Fixed select n + 1 issue by seperating pagnation query and data retreival query.