Skip to content

Python SDK - Faster Message Event traversal #7621

Description

@nickninov

Python SDK can listen to messages dynamically with def listen_messages. Under the hood the function listens for messages.new. Would it be possible to make a new message["event"] property that has the chats as a dict with the chat ID the key? The current implementation of chats is a list and you have to loop through every single message. Example from Agent Demo:

for message in status_toolkit.account.listen_messages():
    content = None
    for chat in message["event"]["chats"]:

        latest_message: dict = chat.get("lastMessage", {})
        if not latest_message:
            continue

        from_public_key = latest_message.get("from")
        if from_public_key != PUBLIC_KEY:
            continue

        content = chat["lastMessage"]["text"]

Python for loops are notoriously slow. I have seen this pattern implemented in other RPC calls.

Related to:

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonPull requests that update Python code

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions