I'm curious do I use realm like it was intended by creators?

Hello everyone, I’m using realmjs in my react native project for a while and I’m curious do I use it like it was made for or not?


Just to give you basic context of the app I’m working on, it’s a chat app where people can communicate if they enjoy their chat they can add each other to friends and chat forever etc. It has all the basic features of all chats: username, online status, profile picture, message edition/deletion, images, voices etc.

How do I use realm

Client syncs its data with backend and store it in realm (all chats, messages, partners data), so basically all needed data is stored locally on a device in realm and on each app’s launch it fetches missed data from the server.

In many components I add listeners to realm. For example I listen for all chats with friends to show them in ChatList, in each Chat I have a listener on messages, then in each message I have listeners to track status (sending, sent, read), was it deleted or not, was it edited or not etc. I do have indexes and query for indexed field and it works fast enough me.

My concerns

Basically I have two concerns:

  1. Is it okay to store all data in realm like I do?
  2. Is is okay to have many many listeners (I clean them up on unmount, so there’re no memory leaks), if a chat has 300 messages then my app will end up with at least 300 realm listeners, I have a feeling that it may hurt the app performance

Yes! That’s a perfectly valid use case.

It’s ok, but may not be the most efficient way to handle that. A chat with 300 messages isn’t a big deal but why add 300 listeners? It would be better to add a listener to a higher level object and be notified of changes within that object, then you have 1 listener per chat.

So the structure like this


the listener would be added to chat_0. Your app will then be notified of deletions, insertions and then modifications within that chat and you can handle those on a per message basis.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.