mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-08 10:28:58 +08:00
`SiteSerializer#post_action_types` and `SiteSerializer#topic_flag_types` both call the `Flag.used_flag_ids` method which executes queries that becomes very slow on sites with alot of records in either the `post_actions` or `reviewable_scores` table. On the `post_actions` table, we execute `SELECT DISTINCT post_action_type_id FROM post_actions`. On the `reviewable_scores` table, we execute `SELECT DISTINCT reviewable_scope_type FROM reviewable_scopes`. The problem with both queries is that it requires the PG planner to scan through every single row in those tables. For our use case, all we actually need is to check if a flag is being referenced by a record in either the `post_actions` or `reviewable_scores` tables. This commit updates the `Flag.used_flag_ids` to accept a `flag_ids` argument and use the argument to check whether the flag ids are referenced in the `post_action_type_id` or `reviewable_scope_type` foreign keys. |
||
|---|---|---|
| .. | ||
| fixtures | ||
| migrate | ||
| post_migrate | ||
| api_test_seeds.rb | ||