Fix a few more bugs where a limited timeline could cause a hanging pagination

This commit is contained in:
Nicolas Werner 2023-07-09 17:32:44 +02:00
parent 7fc7aa2da3
commit 21889f00e7
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -3624,6 +3624,19 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
if (redaction->redacts.empty())
continue;
// persist the first redaction in case this is a limited timeline and it is the first
// event to not break pagination.
if (first && res.limited) {
first = false;
++index;
nhlog::db()->debug("saving redaction '{}'", orderEntry.dump());
cursor.put(lmdb::to_sv(index), orderEntry.dump(), MDB_APPEND);
evToOrderDb.put(txn, event_id, lmdb::to_sv(index));
eventsDb.put(txn, event_id, event.dump());
}
std::string_view oldEvent;
bool success = eventsDb.get(txn, redaction->redacts, oldEvent);
if (!success)
@ -3671,13 +3684,13 @@ Cache::saveTimelineMessages(lmdb::txn &txn,
eventsDb.put(txn, redaction->redacts, event.dump());
eventsDb.put(txn, redaction->event_id, nlohmann::json(*redaction).dump());
} else {
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 (!evToOrderDb.get(txn, event_id, unused_read)) {
first = false;
++index;
nhlog::db()->debug("saving '{}'", orderEntry.dump());