From 470f398122da18d911b57dda9ec3d5a61cab1c05 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Fri, 22 Dec 2023 12:53:24 +0000 Subject: [PATCH] Short circuit if store is empty --- .../openchat-client/src/stores/dataByMessageContextFactory.ts | 1 + frontend/openchat-client/src/stores/failedMessages.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/frontend/openchat-client/src/stores/dataByMessageContextFactory.ts b/frontend/openchat-client/src/stores/dataByMessageContextFactory.ts index bf38773911..39c1c45926 100644 --- a/frontend/openchat-client/src/stores/dataByMessageContextFactory.ts +++ b/frontend/openchat-client/src/stores/dataByMessageContextFactory.ts @@ -48,5 +48,6 @@ export function createMessageContextSpecificObjectStore(init: () => T) { }, clear: (newValue?: MessageContextMap): void => store.set(newValue ?? new MessageContextMap()), + size: (): number => storeValue.size, }; } diff --git a/frontend/openchat-client/src/stores/failedMessages.ts b/frontend/openchat-client/src/stores/failedMessages.ts index 95a39b889b..cc38e75d89 100644 --- a/frontend/openchat-client/src/stores/failedMessages.ts +++ b/frontend/openchat-client/src/stores/failedMessages.ts @@ -25,6 +25,7 @@ function createFailedMessagesStore() { })); }, contains: (key: MessageContext, messageId: bigint): boolean => { + if (store.size() === 0) return false; const chatState = store.get(key); return chatState ? chatState[messageId.toString()] !== undefined : false; },