XF 2.3 Fetch the user entities of all users mentioned or quoted on a thread page in a single query

nocte

Well-known member
I have a thread page with 20 posts. Now I want to change the behavior of mentions and quotes on that page, depending on the user entity of the quoted or mentioned user.

As I don't have the full user entity, but only user_id's and names, I have to fetch the user entities form the database.

Is there any way to kind of collect the user_id's across the page, then fetch the mentioned and quoted users in a single query (for better performance) and finally manipulate the output depending on the user entities (e.g. remove mentions of members of a specific user group)?

Or am I forced to this post by post?

Thanks for any feedback and advice!
 
Unfortunately there are no mentions in Post.emmbed_metadata, so I'd probably start with adding them there.
This shouldn't be much work, the message preparer service already has the data, basically it should be sufficient to just add that in getEmbedMetadata; quotes are already there.

When this is done you can loop through the posts, pluck user_id from Post.embed_metadata and load all required user entities in one go before rendering BB code.
Finally when rendering posts use entity manager findCached to get the cached user entity.

Not tested, just an idea :)
 
Back
Top Bottom