Optimizing Chat Message Searches

Hey all,

My platform uses a chat. Just like any other chat, the user can choose a chat from the left panel. The chats in the repeating group were being sorted by a field called “last message time”. Every time a user created a new message (0.7 WU), I would add that message to a field called “list of messages” and update the “last message time” to current date/time (2.35 WU No idea why making changes to a single thing is this expensive).

So, to reduce WU and make less use of large list fields, I decided to simply search for messages where chat is in current user’s list of chats. This search CURRENTLY only costs around 5 WU, so definitely worth the slight speed reduction.

However, in the future, when the user has thousands of messages, this won’t be ideal. I’d be searching every single message that is inside the user’s chats and then retrieving their chats.

Is there a more effective way of finding all the chats?

I considered doing search for messages: items until X, each item’s chat, but that doesn’t guarantee that all the user’s chats will appear.

Your assistance is greatly appreciated! :slight_smile:

Show only last 7 messages, and by click show more or scroll up load more

If I search only the last 7 messages there’s only going to be up to 7, but most likely 1 chat in the left panel. That’s not what I’m looking for, but thank you for your suggestion!

Don’t understand,by clicking an inbox you will show last 7 messages to on the right hand side, you can have whatever left chats as you like

My repeating group with all the messages is already working as intended.
What I am trying to do is display the user’s chats in order of their last message’s creation date, without actually having a list of “messages” field in the chat datatype.

Currently, I am searching for all messages related to the user and getting each item’s chat: unique elements. Long term, way too many messages will be retrieved from the database, just to get a handful of chats.

Can’t you just search for chats, sorted by last message date?

So, the way to go is , create 2 main data types 1-inboxes, 2-messages. Inboxes will have 2 users, read or undread(yes/no) and a last message,and list of messages.By creating a message you will add to the list which relates to that inbox,and a last message.Left side will have inboxes which is sorted via modified date.And right hand side will contain the messages related to that inbox,pagenated to last 7 items.So,the last part that I don’t have time to explain is to create muting users and showing undread count and creating a notification when message is sent,you can do all that with this logic

If I keep modifying the chat every single time a message is created, then yes, but that gets expensive.

And for the speed loading part , in privacy rules add ‘‘this inboxes list of users contains current user’’ it is visible, that way when you initiate a convo or message an existing user you need to check if you need to create new inbox or message existing one (you need to do that search too and will not consume that much WU).The only part that is left is to reduce WU while creating a message and I dont have solution for that

I appreciate your assistance my friend, I really do. But everything you’ve explained, I already have set up. I am simply trying to optimize my search.

Thanks

So , if you say you did all that , let me know if you find a way for more efficiency, I am trying to not introduce group messaging or video calls, so that they will use whatsapp or else for chatting, it is quite expensive for us.

Sounds good, I will let you know :+1:

This topic was automatically closed after 70 days. New replies are no longer allowed.