bluebubbles-app
bluebubbles-app copied to clipboard
Add index to Message model to speed up queries?
I ran a quick profiling of the Android app after noticing a lot of cpu/battery use when loading chats - about 50% of the CPU time was spent in Chat.getMessages. I took a look at the model (io/message.dart) and noticed there wasn't an index on the id or guid - maybe I'm missing something (not super familiar with ObjectBox), but I'm thinking an index here could improve query performance?
I'll run a few more tests locally but wanted to see if this was already investigated or I missed anything.
Thanks!
So it looks like the index doesn't really matter - but Chat.latestMessage (chat.dart:309) appears to be a very expensive query
I think we need to add the index on the created date column.
Since the date created date is ultimately what we query most by, we can annotate the model with @Index
to make queries faster: https://docs.objectbox.io/entity-annotations
Right here: https://github.com/BlueBubblesApp/bluebubbles-app/blob/d0257c9080e82140602340b48f85fa148721553c/lib/models/io/message.dart#L241
We can also just do this to any column in the DB that we tend to use when querying. It uses more RAM, but increases read speeds