Skip to content

Commit

Permalink
Fixed update operations in DataSync operation not removing database r…
Browse files Browse the repository at this point in the history
…ecords from a subscription when the WHERE condition doesn't match anymore
  • Loading branch information
mpscholten committed Jun 16, 2022
1 parent e6e30de commit 0fd9c2b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion IHP/DataSync/ControllerImpl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ runDataSyncController ensureRLSEnabled installTableChangeTriggers receiveData se
-- results set
isWatchingRecord <- Set.member id <$> readIORef watchedRecordIdsRef
when isWatchingRecord do
sendJSON DidUpdate { subscriptionId, id, changeSet = changesToValue changeSet }
-- The updated record could not be part of the query result set anymore
-- E.g. if it's not matched anymore by the WHERE condition after the update
[(PG.Only isRecordInResultSet)] <- sqlQueryWithRLS ("SELECT EXISTS(SELECT * FROM (" <> theQuery <> ") AS records WHERE records.id = ? LIMIT 1)") (theParams <> [PG.toField id])
if isRecordInResultSet
then sendJSON DidUpdate { subscriptionId, id, changeSet = changesToValue changeSet }
else sendJSON DidDelete { subscriptionId, id }
ChangeNotifications.DidDelete { id } -> do
-- Only send the notifcation if the deleted record was part of the initial
-- results set
Expand Down

0 comments on commit 0fd9c2b

Please sign in to comment.