log event id when sending and when receiving remote echo on sync

This commit is contained in:
Bruno Windels 2021-02-23 19:58:01 +01:00
parent 7b7907add0
commit 0cbf6008a2
3 changed files with 56 additions and 55 deletions

View file

@ -246,7 +246,7 @@ export class Room extends EventEmitter {
} }
let removedPendingEvents; let removedPendingEvents;
if (Array.isArray(roomResponse.timeline?.events)) { if (Array.isArray(roomResponse.timeline?.events)) {
removedPendingEvents = this._sendQueue.removeRemoteEchos(roomResponse.timeline.events, txn); removedPendingEvents = this._sendQueue.removeRemoteEchos(roomResponse.timeline.events, txn, log);
} }
return { return {
summaryChanges, summaryChanges,
@ -405,8 +405,9 @@ export class Room extends EventEmitter {
} }
/** @public */ /** @public */
async fillGap(fragmentEntry, amount) { fillGap(fragmentEntry, amount, log = null) {
// TODO move some/all of this out of Room // TODO move some/all of this out of Room
return this._platform.logger.wrapOrRun(log, "fillGap", async log => {
if (fragmentEntry.edgeReached) { if (fragmentEntry.edgeReached) {
return; return;
} }
@ -418,7 +419,7 @@ export class Room extends EventEmitter {
lazy_load_members: true, lazy_load_members: true,
include_redundant_members: true, include_redundant_members: true,
} }
}).response(); }, {log}).response();
const txn = this._storage.readWriteTxn([ const txn = this._storage.readWriteTxn([
this._storage.storeNames.pendingEvents, this._storage.storeNames.pendingEvents,
@ -429,7 +430,7 @@ export class Room extends EventEmitter {
let gapResult; let gapResult;
try { try {
// detect remote echos of pending messages in the gap // detect remote echos of pending messages in the gap
removedPendingEvents = this._sendQueue.removeRemoteEchos(response.chunk, txn); removedPendingEvents = this._sendQueue.removeRemoteEchos(response.chunk, txn, log);
// write new events into gap // write new events into gap
const gapWriter = new GapWriter({ const gapWriter = new GapWriter({
roomId: this._roomId, roomId: this._roomId,
@ -456,6 +457,7 @@ export class Room extends EventEmitter {
if (this._timeline) { if (this._timeline) {
this._timeline.addGapEntries(gapResult.entries); this._timeline.addGapEntries(gapResult.entries);
} }
});
} }
/** @public */ /** @public */

View file

@ -30,10 +30,7 @@ export class PendingEvent {
constructor({data, remove, emitUpdate, attachments}) { constructor({data, remove, emitUpdate, attachments}) {
this._data = data; this._data = data;
this._attachments = attachments; this._attachments = attachments;
this._emitUpdate = () => { this._emitUpdate = emitUpdate;
console.log("PendingEvent status", this.status, this._attachments && Object.entries(this._attachments).map(([key, a]) => `${key}: ${a.sentBytes}/${a.size}`));
emitUpdate();
};
this._removeFromQueueCallback = remove; this._removeFromQueueCallback = remove;
this._aborted = false; this._aborted = false;
this._status = SendStatus.Waiting; this._status = SendStatus.Waiting;
@ -169,6 +166,7 @@ export class PendingEvent {
const response = await this._sendRequest.response(); const response = await this._sendRequest.response();
this._sendRequest = null; this._sendRequest = null;
this._data.remoteId = response.event_id; this._data.remoteId = response.event_id;
log.set("id", this._data.remoteId);
this._status = SendStatus.Sent; this._status = SendStatus.Sent;
this._emitUpdate("status"); this._emitUpdate("status");
} }

View file

@ -53,7 +53,7 @@ export class SendQueue {
for (let i = 0; i < this._pendingEvents.length; i += 1) { for (let i = 0; i < this._pendingEvents.length; i += 1) {
await log.wrap("send event", async log => { await log.wrap("send event", async log => {
const pendingEvent = this._pendingEvents.get(i); const pendingEvent = this._pendingEvents.get(i);
log.set("id", pendingEvent.queueIndex); log.set("queueIndex", pendingEvent.queueIndex);
try { try {
await this._sendEvent(pendingEvent, log); await this._sendEvent(pendingEvent, log);
} catch(err) { } catch(err) {
@ -93,7 +93,7 @@ export class SendQueue {
} }
} }
removeRemoteEchos(events, txn) { removeRemoteEchos(events, txn, parentLog) {
const removed = []; const removed = [];
for (const event of events) { for (const event of events) {
const txnId = event.unsigned && event.unsigned.transaction_id; const txnId = event.unsigned && event.unsigned.transaction_id;
@ -105,6 +105,7 @@ export class SendQueue {
} }
if (idx !== -1) { if (idx !== -1) {
const pendingEvent = this._pendingEvents.get(idx); const pendingEvent = this._pendingEvents.get(idx);
parentLog.log({l: "removeRemoteEcho", id: pendingEvent.remoteId});
txn.pendingEvents.remove(pendingEvent.roomId, pendingEvent.queueIndex); txn.pendingEvents.remove(pendingEvent.roomId, pendingEvent.queueIndex);
removed.push(pendingEvent); removed.push(pendingEvent);
} }