Skip to content

Commit 0cce9af

Browse files
committed
RoomEvent: Cache event id
It's used to find events and resolving duplicates - pretty performance- sensitive therefore. Caching it can save up to 10% on larger chunks of event processing.
1 parent 99775a9 commit 0cce9af

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Quotient/events/roomevent.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
using namespace Quotient;
1313

14-
RoomEvent::RoomEvent(const QJsonObject& json) : Event(json)
14+
RoomEvent::RoomEvent(const QJsonObject &json) : Event(json), _id(fullJson()[EventIdKey].toString())
1515
{
1616
if (const auto redaction = unsignedPart<QJsonObject>(RedactedCauseKey);
1717
!redaction.isEmpty())
@@ -22,7 +22,7 @@ RoomEvent::~RoomEvent() = default; // Let the smart pointer do its job
2222

2323
QString RoomEvent::displayId() const { return id().isEmpty() ? transactionId() : id(); }
2424

25-
QString RoomEvent::id() const { return fullJson()[EventIdKey].toString(); }
25+
QString RoomEvent::id() const { return _id; }
2626

2727
QDateTime RoomEvent::originTimestamp() const
2828
{
@@ -79,6 +79,7 @@ void RoomEvent::addId(const QString& newId)
7979
Q_ASSERT(id().isEmpty());
8080
Q_ASSERT(!newId.isEmpty());
8181
editJson().insert(EventIdKey, newId);
82+
_id = newId;
8283
qCDebug(EVENTS) << "Event txnId -> id:" << transactionId() << "->" << id();
8384
Q_ASSERT(id() == newId);
8485
}

Quotient/events/roomevent.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class QUOTIENT_API RoomEvent : public Event {
131131
void dumpTo(QDebug dbg) const override;
132132

133133
private:
134+
QString _id;
135+
134136
// RedactionEvent is an incomplete type here so we cannot inline
135137
// constructors using it and also destructors (with 'using', in particular).
136138
event_ptr_tt<RedactionEvent> _redactedBecause;

0 commit comments

Comments
 (0)