Skip to content
This repository was archived by the owner on Jun 13, 2023. It is now read-only.
This repository was archived by the owner on Jun 13, 2023. It is now read-only.

LiveQuery interrupted by external operation on the table it monitors on #247

@bayareahank

Description

@bayareahank

Observed a phenomenon on live query, not sure anybody here has seen something similar before.

Basically I liveQuery on a conversation table for a chat app. On receiving new conversations (new event) or existing conversation having new messages (update event), I will update the UI accordingly. Yet I observed that when I do some operation outside of liveQuery that change (mainly remove current user related record from) the conversation table, liveQuery would sometimes stop responding to live events. Interesting thing is it doesn't stop only with this conversation table liveQuery, all other liveQuery of the same app would stop working as well. Unsubscribe and resubscribe doesn't help in this case. Restart the app, or run Client.shared.reconnect() before doing liveQuery would make it work again.

Sample code look like this:

    listenQuery = PFQuery(className: "Listening")
        .whereKey("person", equalTo: profile.pfObject)
    
    let liveQueryClient = Client.shared
    // liveQueryClient?.reconnect()              // This is the work around. 

    subscription = liveQueryClient!
        .subscribe(listenQuery)
        .handleEvent({
            (_, event) in
            
            switch event {
            case .created(let object):
                guard let listen = Listening(listening: object) else {
                    return
                }
                
                self.newChatHandler(listens: [listen])
                
            case .updated(let object):
                guard let listen = Listening(listening: object) else {
                    return
                }
                
                self.updateExisting(listen)
                
            default:
                break
            }
        })
        .handleError({ (query, error) in
            os_log("startLiveQuery: error: %@", type: .debug, error.localizedDescription)
        })

I am not sure whether not handling delete event has anything to do with this. LiveQuery works fine without touching the DB table, or only adding to the table, and would only stop working (sometimes, not always) when a record is removed. This removal could come from user operation (by blocking a contact, thus removing a conversation), or triggered on the server side by other user, though I haven't pinpointed any exact repeatable source pattern.

I don't know whether anybody here has run into something similar. Reconnect before starting each liveQuery works to me, but doesn't look the right solution.

Setup:

github "BoltsFramework/Bolts-ObjC" "1.9.1"
github "BoltsFramework/Bolts-Swift" "1.5.0"
github "ParsePlatform/Parse-SDK-iOS-OSX" "1.19.1"
github "ParsePlatform/ParseLiveQuery-iOS-OSX" "2.8.0"
github "daltoniam/Starscream" "4.0.4"

Xcode 12.4 Swift 5.3.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions