- Use `.exists?` instead of `.where.any?` and `.where.present?`. `.any?` avoids triggering another sql query for loaded relations, but in this specific case the relation won't be loaded. `.present?` loads the relation to an array and checks if it is empty, which is obviously worse then checking in sql. - Use regular `Hash` instead of `HashWithIndefferentAccess` HWIA comes with a performance overhead since it needs to handle both string and symbol keys. Since the `@cache` is only used in one place, we can control the keys and use a regular Hash instead.
Related issues
Bug #34093: Authorizer cache loads all permitted resources to memory
Refs #34093 - Minor authorizer clean ups
- Use `.exists?` instead of `.where.any?` and `.where.present?`.
`.any?` avoids triggering another sql query for loaded relations, but in
this specific case the relation won't be loaded. `.present?` loads the
relation to an array and checks if it is empty, which is obviously worse
then checking in sql.
- Use regular `Hash` instead of `HashWithIndefferentAccess`
HWIA comes with a performance overhead since it needs to handle both
string and symbol keys. Since the `@cache` is only used in one place, we
can control the keys and use a regular Hash instead.