From 38effda799570e1a0837673d671f364d9c7bd4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Sat, 14 Aug 2021 19:07:50 +0200 Subject: [PATCH] fix: delta calculation --- src/database.rs | 2 +- src/database/rooms.rs | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/database.rs b/src/database.rs index 4e34019..0bf2a44 100644 --- a/src/database.rs +++ b/src/database.rs @@ -108,7 +108,7 @@ fn default_db_cache_capacity_mb() -> f64 { } fn default_sqlite_wal_clean_second_interval() -> u32 { - 15 * 60 // every 15 minutes + 1 * 60 // every minute } fn default_max_request_size() -> u32 { diff --git a/src/database/rooms.rs b/src/database/rooms.rs index 400ce38..fc2bd05 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -510,10 +510,19 @@ impl Rooms { for removed in statediffremoved { if !parent_new.remove(&removed) { + // It was not added in the parent and we removed it parent_removed.insert(removed); } + // Else it was added in the parent and we removed it again. We can forget this change + } + + for new in statediffnew { + if !parent_removed.remove(&new) { + // It was not touched in the parent and we added it + parent_new.insert(new); + } + // Else it was removed in the parent and we added it again. We can forget this change } - parent_new.extend(statediffnew); self.save_state_from_diff( shortstatehash, @@ -557,11 +566,20 @@ impl Rooms { for removed in statediffremoved { if !parent_new.remove(&removed) { + // It was not added in the parent and we removed it parent_removed.insert(removed); } + // Else it was added in the parent and we removed it again. We can forget this change + } + + for new in statediffnew { + if !parent_removed.remove(&new) { + // It was not touched in the parent and we added it + parent_new.insert(new); + } + // Else it was removed in the parent and we added it again. We can forget this change } - parent_new.extend(statediffnew); self.save_state_from_diff( shortstatehash, parent_new,