Revert "Aggregate quickly-sent messages into batches (#4061)" (#4069)

This reverts commit d424945eed.
zio/stable
Eric Bailey 2024-05-16 19:51:26 -05:00 committed by GitHub
parent 1ff15b47f4
commit 0444e69c35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 23 deletions

View File

@ -766,12 +766,12 @@ export class Convo {
logger.DebugContext.convo,
)
const pendingMessages = Array.from(this.pendingMessages.values())
const pendingMessage = Array.from(this.pendingMessages.values()).shift()
/*
* If there are no pending messages, we're done.
*/
if (pendingMessages.length === 0) {
if (!pendingMessage) {
this.isProcessingPendingMessages = false
return
}
@ -779,34 +779,28 @@ export class Convo {
try {
this.isProcessingPendingMessages = true
const {id, message} = pendingMessage
const response = await networkRetry(2, () => {
return this.agent.api.chat.bsky.convo.sendMessageBatch(
return this.agent.api.chat.bsky.convo.sendMessage(
{
items: pendingMessages.map(({message}) => ({
convoId: this.convoId,
message,
})),
},
{encoding: 'application/json', headers: DM_SERVICE_HEADERS},
)
})
const {items} = response.data
for (let i = 0; i < items.length; i++) {
const msg = items[i]
const tempId = pendingMessages[i].id
const res = response.data
/*
* Insert into `newMessages` as soon as we have a real ID. That way, when
* we get an event log back, we can replace in situ.
*/
this.newMessages.set(msg.id, {
...msg,
this.newMessages.set(res.id, {
...res,
$type: 'chat.bsky.convo.defs#messageView',
})
this.pendingMessages.delete(tempId)
}
this.pendingMessages.delete(id)
await this.processPendingMessages()