From 9011c11eafb22eed6930b32f5749886acb3a0e76 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 23 May 2024 11:54:22 -0500 Subject: [PATCH] Reduce polling when app is backgrounded (#4192) --- src/state/messages/events/agent.ts | 8 +++++++- src/state/messages/events/const.ts | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/state/messages/events/agent.ts b/src/state/messages/events/agent.ts index 3759eb3a..0389c77f 100644 --- a/src/state/messages/events/agent.ts +++ b/src/state/messages/events/agent.ts @@ -4,7 +4,10 @@ import {nanoid} from 'nanoid/non-secure' import {networkRetry} from '#/lib/async/retry' import {logger} from '#/logger' -import {DEFAULT_POLL_INTERVAL} from '#/state/messages/events/const' +import { + BACKGROUND_POLL_INTERVAL, + DEFAULT_POLL_INTERVAL, +} from '#/state/messages/events/const' import { MessagesEventBusDispatch, MessagesEventBusDispatchEvent, @@ -287,6 +290,9 @@ export class MessagesEventBus { const lowest = Math.min(DEFAULT_POLL_INTERVAL, ...requested) return lowest } + case MessagesEventBusStatus.Backgrounded: { + return BACKGROUND_POLL_INTERVAL + } default: return DEFAULT_POLL_INTERVAL } diff --git a/src/state/messages/events/const.ts b/src/state/messages/events/const.ts index 921557ce..a7c07d0d 100644 --- a/src/state/messages/events/const.ts +++ b/src/state/messages/events/const.ts @@ -1 +1,2 @@ export const DEFAULT_POLL_INTERVAL = 20e3 +export const BACKGROUND_POLL_INTERVAL = 60e3