⚡️(frontend) optimize countdown check in IsIdleDisconnectModal.tsx
Using Array.includes runs in O(n) on every second of the countdown. Replace the array with a Set to achieve O(1) lookups for better performance.
This commit is contained in:
committed by
aleb_the_flash
parent
555afe4abd
commit
e3e34dbf31
@@ -12,6 +12,7 @@ and this project adheres to
|
|||||||
|
|
||||||
- 🔒️(backend) enhance API input validation to strengthen security #1053
|
- 🔒️(backend) enhance API input validation to strengthen security #1053
|
||||||
- 🦺(backend) strengthen API validation for recording options #1063
|
- 🦺(backend) strengthen API validation for recording options #1063
|
||||||
|
- ⚡️(frontend) optimize few performance caveats #1073
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { useSettingsDialog } from '@/features/settings/hook/useSettingsDialog'
|
|||||||
import { SettingsDialogExtendedKey } from '@/features/settings/type'
|
import { SettingsDialogExtendedKey } from '@/features/settings/type'
|
||||||
|
|
||||||
const IDLE_DISCONNECT_TIMEOUT_MS = 120000 // 2 minutes
|
const IDLE_DISCONNECT_TIMEOUT_MS = 120000 // 2 minutes
|
||||||
const COUNTDOWN_ANNOUNCEMENT_SECONDS = [90, 60, 30]
|
const COUNTDOWN_ANNOUNCEMENT_SECONDS = new Set([90, 60, 30])
|
||||||
const FINAL_COUNTDOWN_SECONDS = 10
|
const FINAL_COUNTDOWN_SECONDS = 10
|
||||||
|
|
||||||
export const IsIdleDisconnectModal = () => {
|
export const IsIdleDisconnectModal = () => {
|
||||||
@@ -58,7 +58,7 @@ export const IsIdleDisconnectModal = () => {
|
|||||||
if (!connectionObserverSnap.isIdleDisconnectModalOpen) return
|
if (!connectionObserverSnap.isIdleDisconnectModalOpen) return
|
||||||
|
|
||||||
const shouldAnnounce =
|
const shouldAnnounce =
|
||||||
COUNTDOWN_ANNOUNCEMENT_SECONDS.includes(remainingSeconds) ||
|
COUNTDOWN_ANNOUNCEMENT_SECONDS.has(remainingSeconds) ||
|
||||||
remainingSeconds <= FINAL_COUNTDOWN_SECONDS
|
remainingSeconds <= FINAL_COUNTDOWN_SECONDS
|
||||||
|
|
||||||
if (shouldAnnounce && remainingSeconds !== lastAnnouncementRef.current) {
|
if (shouldAnnounce && remainingSeconds !== lastAnnouncementRef.current) {
|
||||||
|
|||||||
Reference in New Issue
Block a user