Fetch all contacts to FE to prevent subsequent fetches on contact data

This commit is contained in:
Jack Kingsman
2026-01-19 12:19:23 -08:00
parent a8c34fbd9e
commit a7d0a8f20b
7 changed files with 565 additions and 548 deletions
+12 -3
View File
@@ -45,12 +45,21 @@ async def websocket_endpoint(websocket: WebSocket) -> None:
}
await ws_manager.send_personal(websocket, "health", health_data)
# Contacts
contacts = await ContactRepository.get_all(limit=500)
# Contacts - fetch all by paginating until exhausted
all_contacts = []
chunk_size = 500
offset = 0
while True:
chunk = await ContactRepository.get_all(limit=chunk_size, offset=offset)
all_contacts.extend(chunk)
if len(chunk) < chunk_size:
break
offset += chunk_size
await ws_manager.send_personal(
websocket,
"contacts",
[c.model_dump() for c in contacts],
[c.model_dump() for c in all_contacts],
)
# Channels
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -13,7 +13,7 @@
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
<script type="module" crossorigin src="/assets/index-DviEalHS.js"></script>
<script type="module" crossorigin src="/assets/index-BeFZihz7.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CnRBRJ10.css">
</head>
<body>
+9 -1
View File
@@ -71,7 +71,15 @@ export function useUnreadCounts(
if (conversations.length === 0) return;
try {
const bulkMessages = await api.getMessagesBulk(conversations, UNREAD_FETCH_LIMIT);
// Fetch messages in chunks to avoid huge single requests
const chunkSize = 200;
const bulkMessages: Record<string, Message[]> = {};
for (let i = 0; i < conversations.length; i += chunkSize) {
const chunk = conversations.slice(i, i + chunkSize);
const chunkResult = await api.getMessagesBulk(chunk, UNREAD_FETCH_LIMIT);
Object.assign(bulkMessages, chunkResult);
}
const newUnreadCounts: Record<string, number> = {};
const newMentions: Record<string, boolean> = {};
const newLastMessageTimes: Record<string, number> = {};