Files
music_library/backlog/tasks/ml-190 - Skip-redundant-unsubscriberesubscribe-on-same-record-reconnect.md
T
Claudio Ortolina 54b682a663 ML-190: add same-record reconnect optimization task
From audit doc-25 (Phase 2), Recommendation #2.
2026-05-19 09:46:31 +01:00

1.4 KiB

id, title, status, assignee, created_date, labels, dependencies, documentation, modified_files, priority, ordinal
id title status assignee created_date labels dependencies documentation modified_files priority ordinal
ML-190 Skip redundant unsubscribe+resubscribe on same-record reconnect To Do
2026-05-19 08:42
audit
pubsub
optimization
audits/phase2-pubsub-lifecycle/doc-25 - Audit-Report-PubSub-Subscription-Lifecycle-Phase-2.md
lib/music_library_web/live_helpers/record_actions.ex
low 25000

Description

RecordActions.manage_subscription/2 unsubscribes the old record and subscribes the new record on every handle_params call. When LiveView reconnects to the same record (e.g., after a WebSocket drop within the reconnect grace period), it unsubscribes and resubscribes to the same topic. While harmless (Phoenix.PubSub deduplicates by PID), a same-record check would be a micro-optimization.

Fix: Add a guard: if socket.assigns[:record] && socket.assigns.record.id != new_id, do: Records.unsubscribe(...) — only unsubscribe when the record actually changes.

Source: Audit doc-25 (Phase 2), Recommendation #2.

Acceptance Criteria

  • #1 manage_subscription/2 only calls unsubscribe when old record ID differs from new ID
  • #2 Same-record reconnect skips unsubscribe+resubscribe entirely
  • #3 All existing tests pass