whisper-money/app
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
..
Actions feat: parent/child category tree (#474) 2026-06-03 19:30:12 +02:00
Ai/Agents feat(ai): suggest automation rules during onboarding (#523) 2026-06-13 22:51:15 +02:00
Console/Commands feat(ai): add weekly AI-suggestions cohort report (#530) 2026-06-13 23:23:34 +02:00
Contracts feat(open-banking): finalize bank connection without a session via state token (#498) 2026-06-06 12:12:07 +02:00
Enums feat(ai): suggest automation rules during onboarding (#523) 2026-06-13 22:51:15 +02:00
Events Add Budgeting Feature to Track and Manage Spending (#36) 2026-01-21 15:25:50 +01:00
Exceptions/Banking Handle transient EnableBanking sync failures (#358) 2026-05-06 09:24:05 +02:00
Features feat(transactions): save and reuse transaction filters (#496) 2026-06-05 18:00:14 +02:00
Http fix(cashflow): bound trend window to prevent request timeout (#534) 2026-06-15 12:47:27 +02:00
Jobs feat(ai): suggest automation rules during onboarding (#523) 2026-06-13 22:51:15 +02:00
Listeners feat(users): track last login and last active timestamps (#516) 2026-06-10 11:01:30 +02:00
Mail feat(leads): add user lead re-invite campaign (#432) 2026-05-26 08:35:31 +02:00
Models fix(account): block deletion while subscription or trial is active (#531) 2026-06-14 20:46:44 +02:00
Notifications fix: verify email via signed link without requiring login (#490) 2026-06-05 10:01:32 +02:00
Policies refactor(policies): extract HandlesUserOwnership trait (#478) 2026-06-03 17:43:30 +02:00
Providers feat(ai): suggest automation rules during onboarding (#523) 2026-06-13 22:51:15 +02:00
Rules feat: parent/child category tree (#474) 2026-06-03 19:30:12 +02:00
Services fix(budgets): make period generation idempotent (#533) 2026-06-15 12:44:44 +02:00