Realm Platform Schema Optimisation Advise


#1

I would really appreciate some advice as to how to optimise Realm for my use case.

I would need to sync messages from the Realm Cloud to multiple devices. Each mobile user can define multiple filters (queries) for messages. These messages should then be synced to that user’s mobile device in realtime. We will need to display the results that matched a particular filter (query) in one list at a time, but we would need all matched messages for all filters synced to the local DB. The filters (queries) the user defines could (and most likely will often) result in particular messages being matched by more than one filter (query). We would only need an individual message to be synced to the mobile database once, not multiple times. We also would only want it stored in the mobile database once. What would be the best way to structure the schema to acheive this?

An example schema is:

export const MessageSchema = {
name: “Message”,
primaryKey: “uuid”,
properties: {
/**
* The UUID (or GUID) of the message.
/
uuid: “string”,
/
*
* The source of the message (e.g. Tyrell IO, TFL, etc.)
/
source: “string”,
/
*
* The address the message was sent to. (Delimtted by | )
/
addresses: “string”,
/
*
* The incident type.
/
incidentType: “int”,
/
*
* The meta data tags. (Delimtted by | e.g. CANCELLATION|DELAY|TICKETACCEPT etc.)
/
metaTag: “string”,
/
*
* The UTC timestamp of when the message was sent.
/
sentUtcTimestamp: “date”,
/
*
* True if the message is active.
/
isActive: “bool”,
/
*
* True if the message is the latest.
/
isLatest: “bool”,
/
*
* The message subject.
/
subject: “string”,
/
*
* The message body.
*/
body: “string”
}
};

A user could filter on the source, addresses, incidentType, metaTag, sentUtcTimestamp, isActive and isLatest fields. The body field could in some cases be quite large. Each message will have a unique ID in the form of a UUID.

I literally started a trial for Realm Platform yesterday, so I am very new to it. Any help with how I can get the best out of the platform will be gratefully received.

Many thanks.


#2

@mallan.nexusalpha This will be quite simple using query-based sync on a single class since all subscriptions are additive. The subscription will pull the data from the ROS cloud and write it to the local device where you can then query the data locally - https://docs.realm.io/sync/using-synced-realms/syncing-data#query-based-synchronization

Please keep in mind that you will also want to unsubscribe from queries that you are done with