From f6788ecf1fc576e37617c2eb332f76b729242718 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 5 Jan 2025 15:32:25 +0100 Subject: [PATCH] Break up large key requests into smaller ones Otherwise we might get stuck on requests exceeding the server side size limits forever. --- src/Cache.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Cache.cpp b/src/Cache.cpp index 5e8ba13f..612f2721 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -5389,6 +5389,22 @@ Cache::markUserKeysOutOfDate(lmdb::txn &txn, db_.put(txn, user, nlohmann::json(cacheEntry).dump()); query.device_keys[user] = {}; + + if (query.device_keys.size() >= 32) { + http::client()->query_keys( + query, + [this, sync_token](const mtx::responses::QueryKeys &keys, mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn("failed to query device keys: {} {}", + err->matrix_error.error, + static_cast(err->status_code)); + return; + } + + emit userKeysUpdate(sync_token, keys); + }); + query.device_keys.clear(); + } } if (!query.device_keys.empty())