0

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

CTK
  • 91
  • 2
  • 8
  • do you log in again with same user? – Pavel Poley Aug 19 '19 at 14:13
  • Hi @PavelPoley yes I do log in with same user the second time around. Shouldn't the initial partial be re-used since it already contains the subset of data that user needs? – CTK Aug 19 '19 at 14:56

1 Answers1

0

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.

CTK
  • 91
  • 2
  • 8