whisper-money/app/Http/Controllers/Api
Víctor Falcón 1d4bcd5082
fix(cashflow): bound trend window to prevent request timeout (#534)
## Sentry
Fixes
**[PHP-LARAVEL-3A](https://whisper-money.sentry.io/issues/PHP-LARAVEL-3A)**
— `FatalError: Maximum execution time of 30 seconds exceeded` on `GET
/api/cashflow/trend`. Top frame in Carbon date math (`getUTCUnit`).

## Root cause
`trend()` caps the `months` param at 24, but the `from`/`to` branch
validated only `date` — **no span limit**:

```php
if (isset($validated['from'], $validated['to'])) {
    $start = Carbon::parse($validated['from'])->startOfMonth();
    $end   = Carbon::parse($validated['to'])->endOfMonth();
}
```

The series is then built by `while ($current->lte($end)) { ...;
$current->addMonth(); }`. A request with a huge range (e.g.
`from=0001-01-01&to=9999-12-31`) runs that loop hundreds of thousands of
times — each iteration doing Carbon `format()`/`addMonth()` — and
exhausts the 30s timeout. (Sentry strips query strings, which is why the
captured URL looked param-less.)

The frontend uses the capped `?months=12&to=...` path for the month
view, but the uncapped `?from=...&to=...` path for other period types.

## Fix
Clamp the computed `start` to at most `MAX_TREND_MONTHS` (24) months
before `end`, regardless of branch. Bounds both the month loop and the
transaction query window. 24 matches the existing `months` ceiling.

## Test
`cashflow trend caps the window for unbounded date ranges` — requests
`from=0001-01-01&to=9999-12-31` and asserts exactly 24 data points
returned, in ~0.02s. Without the clamp this loops ~96k months and hangs.
2026-06-15 12:47:27 +02:00
..
AccountController.php refactor(api): standardize serialization via model $hidden (#492) 2026-06-05 13:57:34 +02:00
CashflowAnalyticsController.php fix(cashflow): bound trend window to prevent request timeout (#534) 2026-06-15 12:47:27 +02:00
CategoryMonthlyBreakdownController.php feat(analysis): per-category 12-month spending drawer (#519) 2026-06-11 09:52:53 +02:00
DashboardAnalyticsController.php feat: expand parent categories inline in breakdowns (#486) 2026-06-04 11:19:21 +02:00
ImportDataController.php refactor(api): standardize serialization via model $hidden (#492) 2026-06-05 13:57:34 +02:00
SavedFilterController.php feat(analysis): project-aware transaction analysis (#513) 2026-06-09 15:32:07 +02:00
TransactionAnalysisController.php feat(analysis): shared bar-list breakdowns in transaction drawer (#517) 2026-06-10 12:36:20 +02:00
TransactionController.php refactor(api): standardize serialization via model $hidden (#492) 2026-06-05 13:57:34 +02:00