Problem
While processing a streamed AI response, messages/ai/MessageAI.js calls sock.groupMetadata(jid) each time a completed response fragment needs mention detection. A single response can therefore fetch the same participant list repeatedly, adding avoidable network and processing overhead in active groups.
Expected behavior
One response should reuse group participant metadata when it is safe to do so, while still handling a newly started response or a changed group normally.
Suggested direction
Fetch the group metadata once per response and reuse the participant IDs for mention detection. Keep the change local to the response flow and avoid introducing a long-lived stale cache.
Acceptance criteria
- A single response does not fetch identical group metadata for every fragment.
- Mention detection produces the same results as before.
- Direct-message handling remains unchanged.
- A mocked test or instrumentation demonstrates the reduced lookup count.
Problem
While processing a streamed AI response,
messages/ai/MessageAI.jscallssock.groupMetadata(jid)each time a completed response fragment needs mention detection. A single response can therefore fetch the same participant list repeatedly, adding avoidable network and processing overhead in active groups.Expected behavior
One response should reuse group participant metadata when it is safe to do so, while still handling a newly started response or a changed group normally.
Suggested direction
Fetch the group metadata once per response and reuse the participant IDs for mention detection. Keep the change local to the response flow and avoid introducing a long-lived stale cache.
Acceptance criteria