Skip to content

refactor: make Filter service stateless#30

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-main-service-stateless
Draft

refactor: make Filter service stateless#30
Copilot wants to merge 2 commits into
mainfrom
copilot/refactor-main-service-stateless

Conversation

Copy link
Copy Markdown

Copilot AI commented May 13, 2026

Filter held a private array $forms keyed by $name . $sessionId, accumulating form instances indefinitely on the service object. In long-running processes (FPM workers, Messenger consumers) this leaks memory and can bleed state across requests.

Changes

  • Removed $forms instance variable — service now has zero mutable state
  • Session-backed metadatasaveFilter() writes filter_meta.{name} to the session containing the form class and options; forms are recreated on demand instead of cached
  • filter() — replaces $form->isSubmitted() with $request->query->has('submit-filter') (logically equivalent: the old form was only submitted when saveFilter() called handleRequest(), which itself gated on that param)
  • getForm() — reads filter_meta.{name} from session, recreates the form with the stored type/options, calls handleRequest() only when submit-filter is present so getFormView() still surfaces validation errors correctly; guards against missing metadata with an early return

Session keys now written

Key Content
filter.{name} filter values (unchanged)
filter_sort.{name} sort info (unchanged)
filter_meta.{name} {type, options}new

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants