mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Fix a few db access crashes
This commit is contained in:
parent
2a70847c80
commit
6ad4065de4
2 changed files with 14 additions and 5 deletions
|
@ -787,6 +787,9 @@ Cache::isInitialized()
|
||||||
std::string
|
std::string
|
||||||
Cache::nextBatchToken()
|
Cache::nextBatchToken()
|
||||||
{
|
{
|
||||||
|
if (!env_.handle())
|
||||||
|
throw lmdb::error("Env already closed", MDB_INVALID);
|
||||||
|
|
||||||
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
|
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
|
||||||
std::string_view token;
|
std::string_view token;
|
||||||
|
|
||||||
|
@ -1816,6 +1819,9 @@ Cache::getTimelineRange(const std::string &room_id)
|
||||||
std::optional<uint64_t>
|
std::optional<uint64_t>
|
||||||
Cache::getTimelineIndex(const std::string &room_id, std::string_view event_id)
|
Cache::getTimelineIndex(const std::string &room_id, std::string_view event_id)
|
||||||
{
|
{
|
||||||
|
if (event_id.empty() || room_id.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
|
auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
|
||||||
|
|
||||||
lmdb::dbi orderDb;
|
lmdb::dbi orderDb;
|
||||||
|
|
|
@ -873,11 +873,14 @@ ChatPage::trySync()
|
||||||
|
|
||||||
http::client()->sync(
|
http::client()->sync(
|
||||||
opts,
|
opts,
|
||||||
[this, since = cache::nextBatchToken()](const mtx::responses::Sync &res,
|
[this, since = opts.since](const mtx::responses::Sync &res, mtx::http::RequestErr err) {
|
||||||
mtx::http::RequestErr err) {
|
try {
|
||||||
if (since != cache::nextBatchToken()) {
|
if (since != cache::nextBatchToken()) {
|
||||||
nhlog::net()->warn("Duplicate sync, dropping");
|
nhlog::net()->warn("Duplicate sync, dropping");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
} catch (const lmdb::error &e) {
|
||||||
|
nhlog::db()->warn("Logged out in the mean time, dropping sync");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Reference in a new issue