Fix crash on empty user cache stored

This commit is contained in:
Nicolas Werner 2022-07-01 09:14:17 +02:00
parent 7ebf43ce38
commit 7198cee85e
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9

View file

@ -4442,11 +4442,15 @@ Cache::markUserKeysOutOfDate(lmdb::txn &txn,
std::string_view oldKeys; std::string_view oldKeys;
UserKeyCache cacheEntry; UserKeyCache cacheEntry{};
auto res = db.get(txn, user, oldKeys); auto res = db.get(txn, user, oldKeys);
if (res) { if (res) {
cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size())) try {
.get<UserKeyCache>(); cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size()))
.get<UserKeyCache>();
} catch (std::exception &e) {
nhlog::db()->error("Failed to parse {}: {}", oldKeys, e.what());
}
} }
cacheEntry.last_changed = sync_token; cacheEntry.last_changed = sync_token;