From f8041d176a10359de6456b5f2bfe394bb5ddb219 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 11 Oct 2023 21:07:35 +0200 Subject: [PATCH] Remove old messages only when the db is full or on startup Adds about 40ms of startup delay here, which I think is okay. --- src/ChatPage.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 06d88303..c3f63f7c 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -588,6 +588,10 @@ ChatPage::loadStateFromCache() try { 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(); cache::calculateRoomReadStatus(); @@ -769,14 +773,6 @@ ChatPage::handleSyncResponse(const mtx::responses::Sync &res, const std::string auto updates = cache::getRoomInfo(cache::client()->roomsWithStateUpdates(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) { nhlog::db()->error("lmdb is full: {}", e.what()); cache::deleteOldData();