Parcourir la source

Adjust get_by_chat_id to make sure the async getter lock works

Tulir Asokan il y a 3 ans
Parent
commit
097f9eb79a
1 fichiers modifiés avec 7 ajouts et 3 suppressions
  1. 7 3
      mautrix_signal/portal.py

+ 7 - 3
mautrix_signal/portal.py

@@ -1239,7 +1239,6 @@ class Portal(DBPortal, BasePortal):
         return None
 
     @classmethod
-    @async_getter_lock
     async def get_by_chat_id(cls, chat_id: Union[GroupID, Address], *, receiver: str = "",
                              create: bool = False) -> Optional['Portal']:
         if isinstance(chat_id, str):
@@ -1248,12 +1247,17 @@ class Portal(DBPortal, BasePortal):
             raise ValueError(f"Invalid chat ID type {type(chat_id)}")
         elif not receiver:
             raise ValueError("Direct chats must have a receiver")
+        best_id = chat_id.best_identifier if isinstance(chat_id, Address) else chat_id
+        return await cls._get_by_chat_id(best_id, receiver, create=create, chat_id=chat_id)
+
+    @classmethod
+    @async_getter_lock
+    async def _get_by_chat_id(cls, best_id: str, receiver: str, *, create: bool,
+                              chat_id: Union[GroupID, Address]) -> Optional['Portal']:
         try:
-            best_id = chat_id.best_identifier if isinstance(chat_id, Address) else chat_id
             return cls.by_chat_id[(best_id, receiver)]
         except KeyError:
             pass
-
         portal = cast(cls, await super().get_by_chat_id(chat_id, receiver))
         if portal is not None:
             await portal._postinit()