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
1 changed files with 7 additions and 3 deletions

View File

@ -4442,11 +4442,15 @@ Cache::markUserKeysOutOfDate(lmdb::txn &txn,
std::string_view oldKeys;
UserKeyCache cacheEntry;
UserKeyCache cacheEntry{};
auto res = db.get(txn, user, oldKeys);
if (res) {
cacheEntry = nlohmann::json::parse(std::string_view(oldKeys.data(), oldKeys.size()))
.get<UserKeyCache>();
try {
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;