From ee6d673c77efdb8ee562ece48fdafbe6220a76f1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan <tulir@maunium.net> Date: Wed, 3 Jun 2020 14:59:13 +0300 Subject: [PATCH] Prevent re-syncing threads multiple times in a short time --- mautrix_facebook/user.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mautrix_facebook/user.py b/mautrix_facebook/user.py index a4149f4..3989cab 100644 --- a/mautrix_facebook/user.py +++ b/mautrix_facebook/user.py @@ -53,6 +53,7 @@ class User(BaseUser): _is_logged_in: Optional[bool] _is_connected: Optional[bool] _connection_time: float + _prev_thread_sync: float _session_data: Optional[Dict[str, str]] _db_instance: Optional[DBUser] _sync_lock: SimpleLock @@ -72,6 +73,7 @@ class User(BaseUser): self._is_logged_in = None self._is_connected = None self._connection_time = time.monotonic() + self._prev_thread_sync = -10 self._session_data = session self._db_instance = db_instance self._community_id = None @@ -312,6 +314,10 @@ class User(BaseUser): self.log.exception("Failed to sync contacts") async def sync_threads(self) -> None: + if self._prev_thread_sync + 10 > time.monotonic(): + self.log.debug("Previous thread sync was less than 10 seconds ago, not re-syncing") + return + self._prev_thread_sync = time.monotonic() try: sync_count = config["bridge.initial_chat_sync"] if sync_count <= 0: -- GitLab