Skip to content

Commit

Permalink
Prefer subquery over materialising list of roles (#559)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas McDonald <tom@conceptcoding.co.uk>

Co-authored-by: Rafael Chiarello <rafael.cote@gmail.com>
  • Loading branch information
thomas-mcdonald and cotelha authored Apr 25, 2021
1 parent 61d90f7 commit 3871efb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rolify/adapters/active_record/resource_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def resources_find(roles_table, relation, role_name)
end

def in(relation, user, role_names)
roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}").to_a
roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}")
relation.where("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)} IN (?) AND ((#{quote_table(role_class.table_name)}.resource_id = #{quote_table(relation.table_name)}.#{quote_column(relation.primary_key)}) OR (#{quote_table(role_class.table_name)}.resource_id IS NULL))", roles)
end

Expand Down

0 comments on commit 3871efb

Please sign in to comment.