You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
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));
The text was updated successfully, but these errors were encountered: