summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-07-09 17:32:44 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-07-09 17:32:44 +0200
commit21889f00e77962659104845fa72accd8001fec41 (patch)
tree98c601bb2a070e4306bc72de0bd3aef7bb285aaf /src
parentFix pagination in rooms with a full batch of redactions (diff)
downloadnheko-21889f00e77962659104845fa72accd8001fec41.tar.xz
Fix a few more bugs where a limited timeline could cause a hanging pagination
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index da3e7099..0426f38a 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -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());