简体   繁体   English

部分领域-为什么以及何时创建?

[英]Partial Realms - Why and When are They Created?

I am using Realm and building a Swift mobile app. 我正在使用Realm并构建一个Swift移动应用程序。 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: 这很有意义,如果我检查Realm Cloud,则会创建一个新的部分领域,其路径为:

/db/__partial/DyeOy3OR4sNsqMi2OmDQQEzUa8F3/~7f11cf52 / 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. 我的想法是Realm只会重用已经创建的部分,而是创建一个全新的部分。

/db/__partial/DyeOy3OR4sNsqMi2OmDQQEzUa8F3/~8bc7bc49 / 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: 我也发布在Realm论坛上:

https://forums.realm.io/t/realm-platform-realm-path-partial-s/2833 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. 这不是问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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