fix(plex): make watch import concurrency-safe (upsert), guard toggle
The Plex watch import inserted plex_states via per-row ORM add against a pre-read 'existing' set, which is not safe when the enable call fires more than once while the multi-second import runs (the toggle wasn't disabled during it): overlapping imports raced to INSERT the same (user_id, item_id) rows and all but the first hit a UniqueViolation -> 500 (seen on prod). Rewrite the write path as a chunked PostgreSQL UPSERT (on_conflict_do_update, rows de-duped by item_id) — idempotent and concurrency-safe, Plex still wins on the intersection and Siftlode-only states are untouched. Also disable the Settings toggle (and ignore its onChange) while a sync mutation is pending, so it can't be fired repeatedly; adds a reusable 'disabled' prop to the Switch primitive.
This commit is contained in:
parent
b09963be2b
commit
5592f60e85
3 changed files with 43 additions and 18 deletions
|
|
@ -10,10 +10,12 @@ export function Switch({
|
|||
checked,
|
||||
onChange,
|
||||
label,
|
||||
disabled,
|
||||
}: {
|
||||
checked: boolean;
|
||||
onChange: (v: boolean) => void;
|
||||
label?: string;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
|
|
@ -21,8 +23,9 @@ export function Switch({
|
|||
role="switch"
|
||||
aria-checked={checked}
|
||||
aria-label={label}
|
||||
disabled={disabled}
|
||||
onClick={() => onChange(!checked)}
|
||||
className={`w-9 h-5 rounded-full transition relative shrink-0 ${checked ? "bg-accent" : "bg-border"}`}
|
||||
className={`w-9 h-5 rounded-full transition relative shrink-0 disabled:opacity-50 disabled:cursor-not-allowed ${checked ? "bg-accent" : "bg-border"}`}
|
||||
>
|
||||
<span
|
||||
className={`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-all ${
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue