-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About nested chat messages query efficiency #2838
Comments
Why did you comment out To the actual issue, nothing obvious stands out. Are you using foreign keys for |
@simolus3 the reason why I not using pageNation, but simple just query 20, 40, 60, 80 etc, because I can not judge whether the data was last batch, the UI side so complicated to judge, so simple query them all. But this is not the question, since the laggy happen only first batch, which is only 25 element queried out. I didn't using foregin key, the originalId is just a table field of messages, not foregin key design. To be more specically:
will this more faster? I think roughly this code can work, but I wanna it be a little bit more faster, |
This sounds like the runtime query might be quadratic with the amount of messages looked up. A missing index on So you can try adding an index on |
@simolus3 thank u sir.
Seems no index on originalId can caused repeatly query, make it quadratic. Do u know how can I add such index in my table? Need to do migrate? |
Also, I thought a little bit, this line could cause very serious repeated query, no matter what first batch I query, this will query through all data: final selectReplies = selectOnly(replies) |
Add a @TableIndex(name: 'messages_original_id', columns: {#originalId})
class Messages extends Table {
Yes, you need to increment the schema version and run
Databases apply a bunch of optimizations to the query. When this subquery is executed, the But it's important to know that this is just an assumption. To analyze seemingly slow queries, you need to run an |
@simolus3 Hi, I ended with created a new table which stores message_id and original_id (for current message replys and the messages replied to current message). the speed is fast now. However, my solution seems not same as yours. Possiably your solution maybe even more faster? |
I don't think so, it's likely that your solution sped it up because sqlite3 will create indices automatically for foreign keys. So your solution is essentially the same as mine. |
Hi, I have a nested chat messages query, it need query out base by roomId, and the replied messages as well.
Currently as suggest by community, I have a worked version like this:
But currently I found it caused efficiency issue on my app when messages up to about 500 messages.
If message not too many, it's faster with a blink, but if messages more than about 500, need to load 1s.
However, i have using limited to 25 per query.
Can u guide me some way to make it faster? At least it won't takes too many time when limit to 25
The text was updated successfully, but these errors were encountered: