Skip to content

Commit

Permalink
Merge pull request #2777 from matrix-org/rav/debug_to_device
Browse files Browse the repository at this point in the history
An attempt to debug element-hq/element-web#23548: let's see if we can figure out where the to-device messages are getting lost.
  • Loading branch information
richvdh authored Oct 20, 2022
2 parents bf1137f + 620a8d9 commit fdbbd9b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ToDeviceMessageQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ export class ToDeviceMessageQueue {
public async queueBatch(batch: ToDeviceBatch): Promise<void> {
const batches: ToDeviceBatchWithTxnId[] = [];
for (let i = 0; i < batch.batch.length; i += MAX_BATCH_SIZE) {
batches.push({
const batchWithTxnId = {
eventType: batch.eventType,
batch: batch.batch.slice(i, i + MAX_BATCH_SIZE),
txnId: this.client.makeTxnId(),
});
};
batches.push(batchWithTxnId);
const recips = batchWithTxnId.batch.map((msg) => `${msg.userId}:${msg.deviceId}`);
logger.info(`Created batch of to-device messages with txn id ${batchWithTxnId.txnId} for ${recips}`);
}

await this.client.store.saveToDeviceBatches(batches);
logger.info(`Enqueued to-device messages with txn ids ${batches.map((batch) => batch.txnId)}`);
this.sendQueue();
}

Expand Down Expand Up @@ -118,7 +122,9 @@ export class ToDeviceMessageQueue {
contentMap[item.userId][item.deviceId] = item.payload;
}

logger.info(`Sending batch of ${batch.batch.length} to-device messages with ID ${batch.id}`);
logger.info(
`Sending batch of ${batch.batch.length} to-device messages with ID ${batch.id} and txnId ${batch.txnId}`,
);

await this.client.sendToDevice(batch.eventType, contentMap, batch.txnId);
}
Expand Down

0 comments on commit fdbbd9b

Please sign in to comment.