Skip to content
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

Lag on the long run #26

Open
alexanderbkl opened this issue May 2, 2022 · 0 comments
Open

Lag on the long run #26

alexanderbkl opened this issue May 2, 2022 · 0 comments

Comments

@alexanderbkl
Copy link

alexanderbkl commented May 2, 2022

Due to data pushing (.push()) on the long run, when there would be thousands of messages, it will cause a lot of lag for all of the users due to querying through each of the nodes individually.
I recommend, instead of creating a Chats node reference with all the messages spreaded, organizing the messages into ChatRooms where each child key inside of it is a combination of the senderUid and receiverUid. It could be made by string concatenation or, summing the ASCII values to BigInteger summing both but it's more complicated.
Example:

StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
char[] myCharUid = myUid.toCharArray(); for (char ch : myCharUid)
{ sb1.append((byte) ch);
}
char[] hisCharUid = hisUid.toCharArray(); for (char ch : hisCharUid)
{ sb2.append((byte) ch);
}

String myStringUid = String.valueOf(sb1);
String hisStringUid = String.valueOf(sb2);

BigInteger myBigUid = new BigInteger(myStringUid);
BigInteger hisBigUid = new BigInteger(hisStringUid);

chatRoomId = String.valueOf(myBigUid.add(hisBigUid));

@alexanderbkl alexanderbkl changed the title Lag on long run Lag on the long run May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant