Discourse query causing our PostgreSQL Server CPU usage to rise to 100%

We run a Discourse server ourselves, using an Aurora PostgreSQL Server as it’s database. Our Aurora PostgreSQL server has recently hit 100% CPU usage (previously only maxing out at like 5% CPU usage). The following query is responsible for the high CPU usage:

SELECT "categories"."id" FROM "categories" WHERE ((? AND LENGTH(COALESCE(email_in, ?)) > ? AND email_in_allow_strangers) OR categories.id NOT IN (SELECT category_id FROM category_groups) OR categories.id IN ( SELECT category_id FROM category_groups WHERE permission_type IN (?) AND (group_id = ? OR group_id IN (SELECT group_id FROM group_users WHERE user_id = ?)) ))

This query immediately raises the CPU usage to 100%, but we’re unsure what’s causing this. Does anyone know why our Discourse service would run this query, and why it might cause 100% CPU usage?