At the time of writing, this is how the `TopicPosterSerializer` looks like: ``` class TopicPosterSerializer < ApplicationSerializer attributes :extras, :description has_one :user, serializer: PosterSerializer has_one :primary_group, serializer: PrimaryGroupSerializer has_one :flair_group, serializer: FlairGroupSerializer end ``` Within `PosterSerializer`, the `primary_group` and `flair_group` association is requested on the `user` object. However, the associations have not been loaded on the `user` object at this point leading to the N+1 queries problem. One may wonder why the associations have not been loaded when the `TopicPosterSerializer` has `has_one :primary_group` and `has_one :flair_group`. It turns out that `TopicPoster` is just a struct containing the `user`, `primary_group` and `flair_group` objects. The `primary_group` and `flair_group` ActiveRecord objects are loaded seperately in `UserLookup` and not preloaded when querying for the users. This is done for performance reason so that we are able to load the `primary_group` and `flair_group` records in a single query without duplication. |
||
|---|---|---|
| .. | ||
| fabricators | ||
| fixtures | ||
| helpers | ||
| import_export | ||
| initializers | ||
| integration | ||
| integrity | ||
| jobs | ||
| lib | ||
| mailers | ||
| models | ||
| multisite | ||
| requests | ||
| script/import_scripts | ||
| serializers | ||
| services | ||
| support | ||
| system | ||
| tasks | ||
| views | ||
| rails_helper.rb | ||
| regenerate_swagger_docs | ||
| swagger_helper.rb | ||