Reduce snapshots, add better logic check

This commit is contained in:
Eric Bailey
2024-05-02 20:31:57 -05:00
parent 5ffe4b70d2
commit ef28de37d3
+10 -9
View File
@@ -417,24 +417,19 @@ export class Convo {
private async pollEvents() { private async pollEvents() {
if ( if (
this.status !== ConvoStatus.Ready && this.status === ConvoStatus.Ready ||
this.status !== ConvoStatus.Backgrounded this.status === ConvoStatus.Backgrounded
) ) {
return
if (this.pendingEventIngestion) return if (this.pendingEventIngestion) return
setTimeout(async () => { setTimeout(async () => {
logger.debug(
'Convo: poll',
{pollInterval: this.pollInterval},
logger.DebugContext.convo,
)
this.pendingEventIngestion = this.ingestLatestEvents() this.pendingEventIngestion = this.ingestLatestEvents()
await this.pendingEventIngestion await this.pendingEventIngestion
this.pendingEventIngestion = undefined this.pendingEventIngestion = undefined
this.pollEvents() this.pollEvents()
}, this.pollInterval) }, this.pollInterval)
} }
}
async ingestLatestEvents() { async ingestLatestEvents() {
const response = await this.agent.api.chat.bsky.convo.getLog( const response = await this.agent.api.chat.bsky.convo.getLog(
@@ -449,6 +444,8 @@ export class Convo {
) )
const {logs} = response.data const {logs} = response.data
let needsCommit = false
for (const log of logs) { for (const log of logs) {
/* /*
* If there's a rev, we should handle it. If there's not a rev, we don't * 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.delete(log.message.id)
} }
this.newMessages.set(log.message.id, log.message) this.newMessages.set(log.message.id, log.message)
needsCommit = true
} else if ( } else if (
ChatBskyConvoDefs.isLogDeleteMessage(log) && ChatBskyConvoDefs.isLogDeleteMessage(log) &&
ChatBskyConvoDefs.isDeletedMessageView(log.message) ChatBskyConvoDefs.isDeletedMessageView(log.message)
@@ -496,14 +494,17 @@ export class Convo {
this.pastMessages.delete(log.message.id) this.pastMessages.delete(log.message.id)
this.newMessages.delete(log.message.id) this.newMessages.delete(log.message.id)
this.deletedMessages.delete(log.message.id) this.deletedMessages.delete(log.message.id)
needsCommit = true
} }
} }
} }
} }
} }
if (needsCommit) {
this.commit() this.commit()
} }
}
async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) { async sendMessage(message: ChatBskyConvoSendMessage.InputSchema['message']) {
// Ignore empty messages for now since they have no other purpose atm // Ignore empty messages for now since they have no other purpose atm