Merge pull request #713 from Thulinma/noMoreDuplicates

Fixed duplicate messages appearing in timeline if server sent them
pull/714/head
DeepBlueV7.X 3 years ago committed by GitHub
commit d30401c3c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/Cache.cpp

@ -2999,12 +2999,15 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
eventsDb.put(txn, redaction->redacts, event.dump());
eventsDb.put(txn, redaction->event_id, json(*redaction).dump());
} else {
eventsDb.put(txn, event_id, event.dump());
first = false;
// This check protects against duplicates in the timeline. If the event_id
// is already in the DB, we skip putting it (again) in ordered DBs, and only
// update the event itself and its relations.
std::string_view unused_read;
if (!eventsDb.get(txn, event_id, unused_read)) {
++index;
first = false;
nhlog::db()->debug("saving '{}'", orderEntry.dump());
cursor.put(lmdb::to_sv(index), orderEntry.dump(), MDB_APPEND);
@ -3017,6 +3020,10 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
msg2orderDb.put(txn, event_id, lmdb::to_sv(msgIndex));
}
} else {
nhlog::db()->warn("duplicate event '{}'", orderEntry.dump());
}
eventsDb.put(txn, event_id, event.dump());
auto relations = mtx::accessors::relations(e);
if (!relations.relations.empty()) {
@ -3078,8 +3085,12 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
auto event = mtx::accessors::serialize_event(e);
event_id_val = event["event_id"].get<std::string>();
std::string_view event_id = event_id_val;
eventsDb.put(txn, event_id, event.dump());
// This check protects against duplicates in the timeline. If the event_id is
// already in the DB, we skip putting it (again) in ordered DBs, and only update the
// event itself and its relations.
std::string_view unused_read;
if (!eventsDb.get(txn, event_id, unused_read)) {
--index;
json orderEntry = json::object();
@ -3095,6 +3106,8 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
msg2orderDb.put(txn, event_id, lmdb::to_sv(msgIndex));
}
}
eventsDb.put(txn, event_id, event.dump());
auto relations = mtx::accessors::relations(e);
if (!relations.relations.empty()) {

Loading…
Cancel
Save