Having a lot of data in one "public" partition Realm

Hi,

I know the question in a similar form has already been asked. Nevertheless I want to ask it myself because I couldn’t get my head around it.

I have an app wich uses a Team partition strategy for chats, a private (user) partition strategy for personal data and a “public” partition value for data that everyone can see but only the owner can write/change.

My first question is about the user. If I don’t want to share all the data from the user in the “public” partition, I would need to create two similar collections in my schema (one collection for the publicUser and on for the privateUser). Is there a simpler way than creating two collections that are actually the same (beside the values)?

I understand Realm that every Realm partition I open in the app, saves all the data from that partition on the device. That would mean for my public partition, that every user that creates data in the public partition, would force all the other users to save the created data on their local device as soon as the app opens the “public” Realm.

If that’s correct, then how is an app with Realm Sync and MongoDB like Airbnb possible, which has a lot of public data that can’t be stored locally on devices. Is there a solution to have an only Online partition OR to never save data on the device when there is only a read permission?

Thanks!

I actually have a very similar question… I have a realm with a PUBLIC partition, accessible by all users. Should I expect an issue in the future if this realm grows significantly in size? I set the downloadBeforeOpen parameter, while opening the realm, on .never but I am not 100% sure it alleviates the potential problem.

Hi @Sonisan,

Since the original question was posted, Flexible Sync has been introduced, that solves the general scenario, please have a look at its features.

2 Likes

Hi @Paolo_Manna

Thank you for your reply!
I see… I’ll take a look. Hopefully the transition from partitions is not too painful. :sweat_smile:

Hi @Paolo_Manna,

I managed to transition to flexible sync (which is great by the way!). I am now wondering what would be the “best” way to remove subscriptions in a SwiftUI app.

For example, I have an iOS app where one tab is showing user-generated content (the PUBLIC part I was referring to earlier) that I would like to purge from user’s local storage at some point. At the moment, I am trying to add subscriptions through the MyPublicTab.onAppear() and remove them with MyPublicTab.OnDisappear(). But unfortunately, it looks like removing subscriptions takes a while, which puts the app in an inconsistent state, if the user navigates quickly through the app. The worst case is to have a “clear the cache” option, but any better suggestion is appreciated. :slight_smile:

Hi @Sonisan,

Yes, adding and removing subscriptions that move potentially large data sets is not ideal for performance… You can await for the subscription to be updated, but that’s not great user experience either.

Perhaps you should devise a subscription that can trickle data in and out in small chunks, that would go (almost) unnoticed. For example, you can always be subscribed to the PUBLIC part, but put a time limit (say, since last day, or last visit), and update the limit (up or down) only when the user gets near to it. Nudging subscriptions, instead of removing and creating them, should be much more efficient.

Take all the above with a grain of salt, of course, as Flexible Sync is relatively new, in its current form: for more information, you can read the technical articles from one of the engineers that built it, there are a lot of hints you can take from there!

1 Like