From ef28de37d31d1a41a027eb816617d4420f8cb02d Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 2 May 2024 20:31:57 -0500 Subject: [PATCH] Reduce snapshots, add better logic check --- src/state/messages/convo.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/state/messages/convo.ts b/src/state/messages/convo.ts index 19858fcbe6..6cbf3b78af 100644 --- a/src/state/messages/convo.ts +++ b/src/state/messages/convo.ts @@ -417,23 +417,18 @@ export class Convo { private async pollEvents() { if ( - this.status !== ConvoStatus.Ready && - this.status !== ConvoStatus.Backgrounded - ) - return - if (this.pendingEventIngestion) return + this.status === ConvoStatus.Ready || + this.status === ConvoStatus.Backgrounded + ) { + if (this.pendingEventIngestion) return - setTimeout(async () => { - logger.debug( - 'Convo: poll', - {pollInterval: this.pollInterval}, - logger.DebugContext.convo, - ) - this.pendingEventIngestion = this.ingestLatestEvents() - await this.pendingEventIngestion - this.pendingEventIngestion = undefined - this.pollEvents() - }, this.pollInterval) + setTimeout(async () => { + this.pendingEventIngestion = this.ingestLatestEvents() + await this.pendingEventIngestion + this.pendingEventIngestion = undefined + this.pollEvents() + }, this.pollInterval) + } } async ingestLatestEvents() { @@ -449,6 +444,8 @@ export class Convo { ) const {logs} = response.data + let needsCommit = false + for (const log of logs) { /* * If there's a rev, we should handle it. If there's not a rev, we don't @@ -479,6 +476,7 @@ export class Convo { this.newMessages.delete(log.message.id) } this.newMessages.set(log.message.id, log.message) + needsCommit = true } else if ( ChatBskyConvoDefs.isLogDeleteMessage(log) && ChatBskyConvoDefs.isDeletedMessageView(log.message) @@ -496,13 +494,16 @@ export class Convo { this.pastMessages.delete(log.message.id) this.newMessages.delete(log.message.id) this.deletedMessages.delete(log.message.id) + needsCommit = true } } } } } - this.commit() + if (needsCommit) { + this.commit() + } } async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) {