summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-10-11 21:07:35 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-10-11 21:07:42 +0200
commitf8041d176a10359de6456b5f2bfe394bb5ddb219 (patch)
tree8bf2c1cedd09c3a1009d33d1ae8c17285fd94b33 /src
parentFocus to the message input bar after dragging and dropping a file (diff)
downloadnheko-f8041d176a10359de6456b5f2bfe394bb5ddb219.tar.xz
Remove old messages only when the db is full or on startup
Adds about 40ms of startup delay here, which I think is okay.
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cpp12
1 files 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();