Преглед изворни кода

Add hard limit of how many chats to sync at startup

Tulir Asokan пре 4 година
родитељ
комит
e292c1647e
3 измењених фајлова са 8 додато и 0 уклоњено
  1. 1 0
      mautrix_instagram/config.py
  2. 2 0
      mautrix_instagram/example-config.yaml
  3. 5 0
      mautrix_instagram/user.py

+ 1 - 0
mautrix_instagram/config.py

@@ -60,6 +60,7 @@ class Config(BaseBridgeConfig):
         copy("bridge.displayname_max_length")
 
         copy("bridge.portal_create_max_age")
+        copy("bridge.chat_sync_limit")
         copy("bridge.sync_with_custom_puppets")
         copy("bridge.sync_direct_chat_list")
         copy("bridge.double_puppet_server_map")

+ 2 - 0
mautrix_instagram/example-config.yaml

@@ -78,6 +78,8 @@ bridge:
 
     # Maximum number of seconds since the last activity in a chat to automatically create portals.
     portal_create_max_age: 86400
+    # Maximum number of chats to fetch for startup sync
+    chat_sync_limit: 100
     # Whether or not to use /sync to get read receipts and typing notifications
     # when double puppeting is enabled
     sync_with_custom_puppets: true

+ 5 - 0
mautrix_instagram/user.py

@@ -220,7 +220,9 @@ class User(DBUser, BaseUser):
     async def sync(self) -> None:
         resp = await self.client.get_inbox()
         max_age = self.config["bridge.portal_create_max_age"] * 1_000_000
+        limit = self.config["bridge.chat_sync_limit"]
         min_active_at = (time.time() * 1_000_000) - max_age
+        i = 0
         async for thread in self.client.iter_inbox(start_at=resp):
             portal = await po.Portal.get_by_thread(thread, self.igpk)
             if portal.mxid:
@@ -231,6 +233,9 @@ class User(DBUser, BaseUser):
                 await portal.create_matrix_room(self, thread)
             else:
                 self.log.debug(f"{thread.thread_id} is not active and doesn't have a portal")
+            i += 1
+            if i >= limit:
+                break
         await self.update_direct_chats()
 
         if not self._listen_task: