1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-05 17:02:07 +03:00

Change to event-level beforeRedaction event for efficiency

To avoid an O(n^2) situation with every relations container trying to process
every redaction that may occur in a room, this switches to an event-level
notification, so that the specific relations container who cares can listen to
just the events it wants to know about.
This commit is contained in:
J. Ryan Stinnett
2019-05-13 14:35:39 +01:00
parent f411d50253
commit 3a20114c39
3 changed files with 7 additions and 6 deletions

View File

@@ -661,6 +661,8 @@ utils.extend(module.exports.MatrixEvent.prototype, {
throw new Error("invalid redaction_event in makeRedacted"); throw new Error("invalid redaction_event in makeRedacted");
} }
this.emit("Event.beforeRedaction", this, redaction_event);
// we attempt to replicate what we would see from the server if // we attempt to replicate what we would see from the server if
// the event had been redacted before we saw it. // the event had been redacted before we saw it.
// //

View File

@@ -43,10 +43,6 @@ export default class Relations extends EventEmitter {
this._annotationsByKey = {}; this._annotationsByKey = {};
this._annotationsBySender = {}; this._annotationsBySender = {};
this._sortedAnnotationsByKey = []; this._sortedAnnotationsByKey = [];
if (room) {
room.on("Room.beforeRedaction", this._onBeforeRedaction);
}
} }
/** /**
@@ -78,6 +74,8 @@ export default class Relations extends EventEmitter {
this._relations.add(event); this._relations.add(event);
event.on("Event.beforeRedaction", this._onBeforeRedaction);
this.emit("Relations.add", event); this.emit("Relations.add", event);
} }
@@ -127,7 +125,7 @@ export default class Relations extends EventEmitter {
* For relations that have been redacted, we want to remove them from * For relations that have been redacted, we want to remove them from
* aggregation data sets and emit an update event. * aggregation data sets and emit an update event.
* *
* To do so, we listen for `Room.beforeRedaction`, which happens: * To do so, we listen for `Event.beforeRedaction`, which happens:
* - after the server accepted the redaction and remote echoed back to us * - after the server accepted the redaction and remote echoed back to us
* - before the original event has been marked redacted in the client * - before the original event has been marked redacted in the client
* *
@@ -162,6 +160,8 @@ export default class Relations extends EventEmitter {
}); });
} }
redactedEvent.removeListener("Event.beforeRedaction", this._onBeforeRedaction);
// Dispatch a redaction event on this collection. `setTimeout` is used // Dispatch a redaction event on this collection. `setTimeout` is used
// to wait until the next event loop iteration by which time the event // to wait until the next event loop iteration by which time the event
// has actually been marked as redacted. // has actually been marked as redacted.

View File

@@ -1011,7 +1011,6 @@ Room.prototype._addLiveEvent = function(event, duplicateStrategy) {
// if we know about this event, redact its contents now. // if we know about this event, redact its contents now.
const redactedEvent = this.getUnfilteredTimelineSet().findEventById(redactId); const redactedEvent = this.getUnfilteredTimelineSet().findEventById(redactId);
if (redactedEvent) { if (redactedEvent) {
this.emit("Room.beforeRedaction", redactedEvent, event, this);
redactedEvent.makeRedacted(event); redactedEvent.makeRedacted(event);
this.emit("Room.redaction", event, this); this.emit("Room.redaction", event, this);