28e6af88aa
If we don't call #to_a, we're relying on the members already being loaded from elsewhere. Otherwise we'll do a separate query for each user: [1] pry(main)> Project.first.team.members.include?(User.first) Project Load (0.7ms) SELECT "projects".* FROM "projects" ORDER BY "projects"."id" ASC LIMIT 1 ↳ (pry):3 User Load (1.8ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 ↳ (pry):3 User Exists (0.6ms) SELECT 1 AS one FROM "users" INNER JOIN "project_authorizations" ON "users"."id" = "project_authorizations"."user_id" WHERE "project_authorizations"."project_id" = $1 AND "users"."id" = $2 LIMIT 1 [["project_id", 1], ["id", 1]] ↳ (pry):3 => true [2] pry(main)> Project.first.team.members.to_a.include?(User.first) Project Load (12.8ms) SELECT "projects".* FROM "projects" ORDER BY "projects"."id" ASC LIMIT 1 ↳ (pry):1 User Load (9.6ms) SELECT "users".* FROM "users" INNER JOIN "project_authorizations" ON "users"."id" = "project_authorizations"."user_id" WHERE "project_authorizations"."project_id" = $1 [["project_id", 1]] ↳ (pry):1 User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 ↳ (pry):1 => true |
||
---|---|---|
.. | ||
application_setting | ||
ci | ||
clusters | ||
concerns | ||
project_policy | ||
base_policy.rb | ||
commit_policy.rb | ||
commit_status_policy.rb | ||
deploy_key_policy.rb | ||
deploy_token_policy.rb | ||
deployment_policy.rb | ||
environment_policy.rb | ||
external_issue_policy.rb | ||
global_policy.rb | ||
group_label_policy.rb | ||
group_member_policy.rb | ||
group_policy.rb | ||
issuable_policy.rb | ||
issue_policy.rb | ||
merge_request_policy.rb | ||
namespace_policy.rb | ||
nil_policy.rb | ||
note_policy.rb | ||
personal_snippet_policy.rb | ||
project_label_policy.rb | ||
project_member_policy.rb | ||
project_policy.rb | ||
project_snippet_policy.rb | ||
protected_branch_policy.rb | ||
user_policy.rb |