perf(settlement,rating): paginate 3 unbounded list endpoints (M10-M12)

- M10 GET /settlement: was unbounded; add page/limit + countByUser + data.meta.
- M11 GET /admin/comments/pending: paginate findPending + countPending.
- M12 GET /comments/{doctor}: paginate the fetch-joined roots query via
  Paginator(fetchJoinCollection) + countApprovedRootsByDoctor.

All keep the existing { data: { data: [...] } } envelope and add data.meta
(backward compatible). Default limit 50 / max 100.

Regressions: SettlementListPaginationTest, CommentPaginationTest (both fail
without the limits). Also de-flaked SendCodeMobileRateLimitTest (randomised the
IP block so the persistent per-IP limiter buckets don't accumulate across runs).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-28 20:36:41 +03:30
co-authored by Claude Opus 4.8
parent 447482c2ea
commit 61ac775175
10 changed files with 175 additions and 24 deletions
@@ -203,14 +203,25 @@ class SettlementController extends BaseController
]
)]
#[Route('/api/v1/settlement', methods: ['GET'])]
public function listMine(#[CurrentUser] User $user): JsonResponse
public function listMine(Request $request, #[CurrentUser] User $user): JsonResponse
{
$page = max(1, (int) $request->query->get('page', 1));
$limit = min(100, max(1, (int) $request->query->get('limit', 50)));
$settlements = array_map(
fn(Settlement $s) => $s->toArray(),
$this->settlementRepo->findByUser($user)
$this->settlementRepo->findByUser($user, $limit, ($page - 1) * $limit)
);
$total = $this->settlementRepo->countByUser($user);
return $this->success(['data' => $settlements]);
return $this->success([
'data' => $settlements,
'meta' => [
'totalRecords' => $total,
'totalPages' => (int) ceil($total / $limit),
'currentPage' => $page,
],
]);
}
#[OA\Get(
@@ -20,9 +20,14 @@ class SettlementRepository extends ServiceEntityRepository
}
/** @return Settlement[] */
public function findByUser(User $user): array
public function findByUser(User $user, int $limit = 50, int $offset = 0): array
{
return $this->findBy(['user' => $user], ['createdAt' => 'DESC']);
return $this->findBy(['user' => $user], ['createdAt' => 'DESC'], $limit, $offset);
}
public function countByUser(User $user): int
{
return $this->count(['user' => $user]);
}
/** Balance = sum of credits - sum of debits from wallet_transactions */