FEATURE - group modetators visual indicator (PR #10310)

Add class to post. Memoize some calls.

Group Moderators adds classes, etc., to posts (and tests)

additional assertion


The title of this pull request changed from “WIP - group modetators visual indicator” to "FEATURE - group modetators visual indicator

This will be at least an N+1 query right? Unless I’m mistaken you will be querying this once per post returned which is quite expensive.

I suspect you will need another strategy here - for example the topic view could check if the category of the topic is reviewable by a group, and if so do one query for the moderators and pass the list to the serializer.

You’re right. I’ve been getting more uncomfortable with the way I initially implemented this the further I’ve gone in to it.

I’ll have a go at a light refactor to solve the problem you mention.

@eviltrout I added a method on TopicView that will have the user_ids of any category group moderators for the current batch of posts. If the PostSerializer is called from the context of the TopicView, it will use that memoized value.

If PostSerializer is called outside of a TopicView context (eg, when you create a new post), it will fall back to the previous way of doing it on a per-post basis.

Is this implementation the sort of thing you had in mind?

Looks good! Thanks for fixing the n+1.