Remove old messages only when the db is full or on startup

Adds about 40ms of startup delay here, which I think is okay.
pull/1583/head
Nicolas Werner 1 year ago
parent 13a540646f
commit f8041d176a
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
  1. 12
      src/ChatPage.cpp

@ -588,6 +588,10 @@ ChatPage::loadStateFromCache()
try { try {
olm::client()->load(cache::restoreOlmAccount(), cache::client()->pickleSecret()); olm::client()->load(cache::restoreOlmAccount(), cache::client()->pickleSecret());
nhlog::db()->info("Removing old cached messages");
cache::deleteOldData();
nhlog::db()->info("Message removal done");
emit initializeEmptyViews(); emit initializeEmptyViews();
cache::calculateRoomReadStatus(); cache::calculateRoomReadStatus();
@ -769,14 +773,6 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string
auto updates = cache::getRoomInfo(cache::client()->roomsWithStateUpdates(res)); auto updates = cache::getRoomInfo(cache::client()->roomsWithStateUpdates(res));
emit syncUI(std::move(res)); emit syncUI(std::move(res));
// if we process a lot of syncs (1 every 200ms), this means we clean the
// db every 100s
static int syncCounter = 0;
if (syncCounter++ >= 500) {
cache::deleteOldData();
syncCounter = 0;
}
} catch (const lmdb::map_full_error &e) { } catch (const lmdb::map_full_error &e) {
nhlog::db()->error("lmdb is full: {}", e.what()); nhlog::db()->error("lmdb is full: {}", e.what());
cache::deleteOldData(); cache::deleteOldData();

Loading…
Cancel
Save