discourse/db
Alan Guo Xiang Tan 684569c30e
PERF: Avoid slow preloading in SiteSerializer (#33283)
`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.
2025-06-25 15:03:34 +08:00
..
fixtures FEATURE: system themes (#32681) 2025-06-13 10:36:31 +08:00
migrate PERF: Avoid slow preloading in SiteSerializer (#33283) 2025-06-25 15:03:34 +08:00
post_migrate FIX: latest duplicated groups to about components (#33003) 2025-06-04 09:48:18 +08:00
api_test_seeds.rb