Closed paOol closed 3 years ago
How many messages should the array hold before starting to remove them? Also what is the amount of time where a message is considered "old"?
I've left it running over night and had no memory issues, so we can be a bit on the conservative side regarding how many messages to store.
Kinda arbitrary, but maybe 400 msgs?
"old" doesn't refer to duration, but rather anything past 400 for example.
Here's what I have for a solution: when the array of messages exceeds 400, return the last 400 items of the array.
// ChatMessage.tsx
...
const ChatMessage: React.FunctionComponent<IChatmessageProps> = ({ messages }: IChatmessageProps) => {
return (
<React.Fragment>
{(messages.length > 400
? messages.slice(Math.max(messages.length - 400, 0))
: messages)
.map((x: Chat, i: number) => {...})}
</React.Fragment>
);
};
See PR #16
instead of letting the state hold an array of infinite items,
the older messages should be removed to maintain a max array size of XX.
the logic should be something like
once the length of messages exceeds XX, remove X amount of oldest items in the array, and update the state.