简体   繁体   中英

Partial Realms - Why and When are They Created?

I am using Realm and building a Swift mobile app. I am really struggling to understand why and when Partial realms are created.

Here is my scenario:

a user logs in to the app and is brought to the first view controller.

In the first view controller in view did load, I am executing a query to get the current user, subscribing to the query and adding an observer to let me know when the data is synced:

let currentUserArr = realm.objects(DBUser.self).filter("id == %@", userId)
self.subscription = currentUserArr.subscribe(named: "current user")
self.subscriptionToken = self.subscription.observe(\.state, options: .initial) { state in
            switch state {
            case .creating:
                print("creating")
            case .pending:
                print("pending")
            case .complete:
                print("complete")
                self.artist = currentUserArr[0]
            case .invalidated:
                print("invalidated")
            case .error(let err):
                //seal.reject(err)
                print(err)
            }
}

This makes sense that if I check Realm Cloud, I have a new partial realm created with path as:

/db/__partial/DyeOy3OR4sNsqMi2OmDQQEzUa8F3/~7f11cf52

However, here is where my confusion starts. I log the user out. I log back in and again the code above executes. My thought would be that Realm would just reuse the partial already created, but instead it creates an entirely new partial.

/db/__partial/DyeOy3OR4sNsqMi2OmDQQEzUa8F3/~8bc7bc49

Is this by design or should I somehow be reusing partials rather than having a new one created every time a query is executed (even if it is executed by the same user)?

I have posted on Realm Forums as well:

https://forums.realm.io/t/realm-platform-realm-path-partial-s/2833

I don't believe I was actually logging the current sync user out. Upon further testing, once I did log out and log back in, the existing partial was re-used. This is a non-issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM