Fix infinite pagination properly now.

This commit is contained in:
Nicolas Werner 2020-10-23 19:42:12 +02:00
parent 1ab20e0ee3
commit 4797b9fa96
4 changed files with 19 additions and 5 deletions

View file

@ -2712,8 +2712,19 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message
} }
} }
if (res.chunk.empty()) if (res.chunk.empty()) {
if (lmdb::dbi_get(txn, orderDb, lmdb::val(&index, sizeof(index)), val)) {
auto orderEntry = json::parse(std::string_view(val.data(), val.size()));
orderEntry["prev_batch"] = res.end;
lmdb::dbi_put(txn,
orderDb,
lmdb::val(&index, sizeof(index)),
lmdb::val(orderEntry.dump()));
nhlog::db()->debug("saving '{}'", orderEntry.dump());
txn.commit();
}
return index; return index;
}
std::string event_id_val; std::string event_id_val;
for (const auto &e : res.chunk) { for (const auto &e : res.chunk) {

View file

@ -54,8 +54,11 @@ EventStore::EventStore(std::string room_id, QObject *)
&EventStore::oldMessagesRetrieved, &EventStore::oldMessagesRetrieved,
this, this,
[this](const mtx::responses::Messages &res) { [this](const mtx::responses::Messages &res) {
if (cache::client()->previousBatchToken(room_id_) == res.end) if (cache::client()->previousBatchToken(room_id_) == res.end) {
noMoreMessages = true; noMoreMessages = true;
emit fetchedMore();
return;
}
uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res); uint64_t newFirst = cache::client()->saveOldMessages(room_id_, res);
if (newFirst == first) if (newFirst == first)