I recently launched a simple chat app with Bubble. It has a single chatroom and the app consists of 3 data types:
- Users
- Messages: message (text), photo (media), reply (message)
- Media: caption (text), url (file)
As you can see, the data structure is fairly simple. In the app itself, I just have a RG does a search for Messages and grabs the latest 12 items each time. I used to display all messages, but felt it was taken a toll on my WU so I started limiting it to 12 items.
Given how simple my app is, I feel like it is using much more WU than it should. In other words, I feel like I am missing a key component to making my app more efficient. As seen more the screenshots, in just a few days, I have consumed over 96K in WU and close to 90% of that is due to the Search for Messages query. As of the time of the screenshots were taken, I had about 1,500 messages stored in the Message data type.
What are some ways I can optimize my app to lower the WU? I know itâs very common for people to load the data once into a custom state during the initial page load, but that doesnât really work for a âreal-timeâ chat system in my case.
Any suggestions would be much appreciated!
Can you show us the full Search for Messages expression (its constraints, where itâs used)?
The WU seems high based on your usage.
It has 2 constrains. One is to hide any messages that over 60 minutes old and ignore messages that been marked as deleted.
I think whatâs probably happening is your âReal Date/Timeâ plugin is updating regularly. Every time the current time updates, that is likely triggering a new search (as the constraints have changed).
Replace the Real Date/time constraint with Current date/time. That wonât normally update until the page is refreshed, but should cut your WU usage.
Let me know if that works for you!
Unfortunately, I am not sure I can get rid of that date plugin. If I use Bubbleâs built-in Current date/time, the message disappearing feature wouldnât work unless the user refreshes the page to update the time, correct?
Sure, but why do the messages disappear after 60 minutes?
Itâs way cheaper (WU) to show them all of their messages and update it when a message is sent, than it is to show 12, but do the search 60 times per minute or however often that plugin causes updates.
Itâs really to replicate the Disappearing Messages feature thatâs seen in a lot of chat apps these days: https://faq.whatsapp.com/673193694148537.
Do you have any suggestions on how to achieve this without using a plugin that updates the time in real-time?
When a message is sent, schedule a backend workflow that runs at Current date/time + 60 minutes.
In that backend workflow, set the Messageâs âdeletedâ to âyesâ.
Add privacy rules such that users cannot see their deleted messages.
Search for all messages where deleted
is no
, and any deleted ones will be hidden once an hour is up (as the scheduled workflow will run and mark it as deleted), and the privacy rules will restrict it.
1 Like
This is a brilliant suggestion, completely forgot to take advantage of backend workflows. Let me try to implement this and monitor the WU in the next few days to see if thereâs a drop in usage. Thanks for your help!
1 Like