Update constraint of LiveQuery

Let’s have an array of group’s objectId that I want to subscribe:

var arrayOfGroupObjectIds: [String] = ["aaa", "bbb", "ccc"]
let groupQuery = Group.query(containedIn(key: "objectId", array: arrayOfGroupObjectIds))
groupSubscription = groupQuery.subscribeCallback
groupSubscription?.handleEvent { _, event in
     switch event {
     ....
     }
}

When the array changes (objectId added or removed) what would be the proper way to update LiveQuery? Do I understand it correctly, that the query should be unsubscribed and then set again?

groupSubscription?.query.unsubscribe()
let groupQuery = Group.query(containedIn(key: "objectId", array: arrayOfGroupObjectIds))
groupSubscription = groupQuery.subscribeCallback

Or the groupSubscription?.query.unsubscribe() is not needed and the query gets updated without leaving zombie on the server side?

Thank you!

As long as I know, I believe you need to unsubscribe and then subscribe to the new query.

1 Like