discourse/spec
Alan Guo Xiang Tan 4eee1320b0
PERF: Fix N+1 queries when serializing topic posters (#19545)
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.
2022-12-22 05:30:29 +08:00
..
fabricators DEV: Remove fabrication hack for staff (#19528) 2022-12-21 14:02:40 +02:00
fixtures DEV: Fix png optimization test flakyness (#19535) 2022-12-20 16:05:14 -03:00
helpers FEATURE: Optionally allow a separate `s3_asset_cdn_url` to be specified (#19284) 2022-12-08 10:36:20 +00:00
import_export DEV: Add a rake task to export/import translation overrides (#18487) 2022-10-05 15:22:16 -04:00
initializers Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
integration FEATURE: Track API and user API requests (#19186) 2022-11-29 13:07:42 +02:00
integrity DEV: Compatibility with Ruby 3.2 (#19303) 2022-12-13 16:03:53 -03:00
jobs DEV: Skip push notifications for active online users (#19502) 2022-12-19 20:17:40 +00:00
lib DEV: Fix FinalDestination::Resolver race condition (#19558) 2022-12-21 16:02:24 +00:00
mailers SECURITY: Filter tags in user notifications for visibility (#19239) 2022-11-29 10:35:41 -06:00
models FIX: Don't assume a clean slate in tests (#19499) 2022-12-19 12:12:03 -06:00
multisite DEV: Change HashtagAutocompleteService to use DiscoursePluginRegistry (#19491) 2022-12-19 13:46:17 +10:00
requests PERF: Fix N+1 queries when serializing topic posters (#19545) 2022-12-22 05:30:29 +08:00
script/import_scripts DEV: Remove remaining hardcoded ids (#18735) 2022-10-25 15:29:09 +08:00
serializers DEV: Remove enable_whispers site setting (#19196) 2022-12-16 18:42:51 +02:00
services FIX: Include tags inside tag groups for hashtag search (#19539) 2022-12-21 15:14:50 +10:00
support DEV: Change HashtagAutocompleteService to use DiscoursePluginRegistry (#19491) 2022-12-19 13:46:17 +10:00
system UX: Hashtag autocomplete styling (#19426) 2022-12-19 12:31:45 +01:00
tasks FIX: Allow attr updates of over-size-limit uploads (#18986) 2022-11-11 17:56:11 +01:00
views DEV: use structured data in topic-list for referencing only (#16235) 2022-12-05 18:00:32 +02:00
rails_helper.rb DEV: Change HashtagAutocompleteService to use DiscoursePluginRegistry (#19491) 2022-12-19 13:46:17 +10:00
regenerate_swagger_docs DEV: Add API docs for uploads and API doc watcher (#15387) 2021-12-23 08:40:15 +10:00
swagger_helper.rb DEV: Update rubocop (#18754) 2022-10-26 09:05:15 +08:00