From 0e49b5f972e442632cf4083c1c5c8d994b34da46 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 6 May 2020 13:47:28 -0400 Subject: [PATCH] Write-lock when refiltering --- TODO.md | 1 + src/backend/models/filters.py | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/TODO.md b/TODO.md index c7cceaf2..a6cc70d7 100644 --- a/TODO.md +++ b/TODO.md @@ -11,6 +11,7 @@ - fix left rooms opacity - fix escape keybinds (filter rooms, message selection) - fix nio 429 +- fix python getting stuck when loading large room - account delegates refactor - lag when switching accounts diff --git a/src/backend/models/filters.py b/src/backend/models/filters.py index c6beb802..648b7472 100644 --- a/src/backend/models/filters.py +++ b/src/backend/models/filters.py @@ -55,23 +55,24 @@ class ModelFilter(ModelProxy): def refilter(self) -> None: - take_out = [] - bring_back = [] + with self._write_lock: + take_out = [] + bring_back = [] - for key, item in sorted(self.items(), key=lambda kv: kv[1]): - if not self.accept_item(item): - take_out.append(key) + for key, item in sorted(self.items(), key=lambda kv: kv[1]): + if not self.accept_item(item): + take_out.append(key) - for key, item in self.filtered_out.items(): - if self.accept_item(item): - bring_back.append(key) + for key, item in self.filtered_out.items(): + if self.accept_item(item): + bring_back.append(key) - with self.batch_remove(): - for key in take_out: - self.filtered_out[key] = self.pop(key) + with self.batch_remove(): + for key in take_out: + self.filtered_out[key] = self.pop(key) - for key in bring_back: - self[key] = self.filtered_out.pop(key) + for key in bring_back: + self[key] = self.filtered_out.pop(key) class FieldSubstringFilter(ModelFilter):