minimal streamplace frontend
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix max message limit

Juliet 4057cc9f 3f3711be

+10 -2
+10 -2
src/components/Chat.tsx
··· 22 22 class?: string; 23 23 } 24 24 25 - const MAX_MESSAGES = 500; 25 + const MAX_MESSAGES = 200; 26 26 27 27 function getAuthorColor(msg: ChatMessage): string { 28 28 const color = msg.chatProfile?.color; ··· 114 114 115 115 const addMessage = (msg: ChatMessage) => { 116 116 setMessages((prev) => { 117 - // Insert sorted by indexedAt to handle backfill arriving in reverse order 118 117 const msgTime = new Date(msg.indexedAt).getTime(); 118 + const lastTime = prev.length > 0 ? new Date(prev[prev.length - 1].indexedAt).getTime() : 0; 119 + 120 + // Fast path: message is newest (common case for live messages) 121 + if (msgTime >= lastTime) { 122 + const next = prev.length >= MAX_MESSAGES ? [...prev.slice(1), msg] : [...prev, msg]; 123 + return next; 124 + } 125 + 126 + // Slow path: backfill arriving out of order 119 127 let i = prev.length; 120 128 while (i > 0 && new Date(prev[i - 1].indexedAt).getTime() > msgTime) { 121 129 i--;