Don't check user database when handling ephemeral events
This commit is contained in:
@@ -328,17 +328,15 @@ class MatrixHandler(BaseMatrixHandler):
|
|||||||
return
|
return
|
||||||
|
|
||||||
for user_id, event_id in receipts:
|
for user_id, event_id in receipts:
|
||||||
user = await u.User.get_by_mxid(user_id).ensure_started()
|
user = u.User.get_by_mxid(user_id, check_db=False, create=False)
|
||||||
if not await user.is_logged_in():
|
if user and await user.is_logged_in():
|
||||||
continue
|
await portal.mark_read(user, event_id)
|
||||||
await portal.mark_read(user, event_id)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def handle_presence(user_id: UserID, presence: PresenceState) -> None:
|
async def handle_presence(user_id: UserID, presence: PresenceState) -> None:
|
||||||
user = await u.User.get_by_mxid(user_id).ensure_started()
|
user = u.User.get_by_mxid(user_id, check_db=False, create=False)
|
||||||
if not await user.is_logged_in():
|
if user and await user.is_logged_in():
|
||||||
return
|
await user.set_presence(presence == PresenceState.ONLINE)
|
||||||
await user.set_presence(presence == PresenceState.ONLINE)
|
|
||||||
|
|
||||||
async def handle_typing(self, room_id: RoomID, now_typing: Set[UserID]) -> None:
|
async def handle_typing(self, room_id: RoomID, now_typing: Set[UserID]) -> None:
|
||||||
portal = po.Portal.get_by_mxid(room_id)
|
portal = po.Portal.get_by_mxid(room_id)
|
||||||
@@ -353,11 +351,9 @@ class MatrixHandler(BaseMatrixHandler):
|
|||||||
if is_typing and was_typing:
|
if is_typing and was_typing:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
user = await u.User.get_by_mxid(user_id).ensure_started()
|
user = u.User.get_by_mxid(user_id, check_db=False, create=False)
|
||||||
if not await user.is_logged_in():
|
if user and await user.is_logged_in():
|
||||||
continue
|
await portal.set_typing(user, is_typing)
|
||||||
|
|
||||||
await portal.set_typing(user, is_typing)
|
|
||||||
|
|
||||||
self.previously_typing[room_id] = now_typing
|
self.previously_typing[room_id] = now_typing
|
||||||
|
|
||||||
|
|||||||
@@ -459,7 +459,8 @@ class User(AbstractUser, BaseUser):
|
|||||||
# region Class instance lookup
|
# region Class instance lookup
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_by_mxid(cls, mxid: UserID, create: bool = True) -> Optional['User']:
|
def get_by_mxid(cls, mxid: UserID, create: bool = True, check_db: bool = True
|
||||||
|
) -> Optional['User']:
|
||||||
if not mxid:
|
if not mxid:
|
||||||
raise ValueError("Matrix ID can't be empty")
|
raise ValueError("Matrix ID can't be empty")
|
||||||
|
|
||||||
@@ -468,10 +469,11 @@ class User(AbstractUser, BaseUser):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
user = DBUser.get_by_mxid(mxid)
|
if check_db:
|
||||||
if user:
|
user = DBUser.get_by_mxid(mxid)
|
||||||
user = cls.from_db(user)
|
if user:
|
||||||
return user
|
user = cls.from_db(user)
|
||||||
|
return user
|
||||||
|
|
||||||
if create:
|
if create:
|
||||||
user = cls(mxid)
|
user = cls(mxid)
|
||||||
|
|||||||
Reference in New Issue
Block a user