Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
limit these queries to fewer columns
Browse files Browse the repository at this point in the history
This shortens these role-based queries (executed every time a non-admin user
accesses a build, rack or device)
  • Loading branch information
karenetheridge committed Dec 12, 2019
1 parent 9e15928 commit 479d17a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/Conch/DB/ResultSet/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ sub user_has_role ($self, $user_id, $role) {
my $via_user_rs = $self
->search_related('user_build_roles', { user_id => $user_id })
->with_role($role)
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

my $via_org_rs = $self
->related_resultset('organization_build_roles')
->with_role($role)
->related_resultset('organization')
->search_related('user_organization_roles', { user_id => $user_id })
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

return $via_user_rs->union_all($via_org_rs)->exists;
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Conch/DB/ResultSet/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ sub user_has_role ($self, $user_id, $role) {
->related_resultset('build')
->search_related('user_build_roles', { user_id => $user_id })
->with_role($role)
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

my $via_org_rs = $self
->related_resultset('build')
->related_resultset('organization_build_roles')
->with_role($role)
->related_resultset('organization')
->search_related('user_organization_roles', { user_id => $user_id })
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

return 1 if $via_user_rs->union_all($via_org_rs)->exists;

Expand Down
9 changes: 6 additions & 3 deletions lib/Conch/DB/ResultSet/Rack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,25 @@ sub user_has_role ($self, $user_id, $role) {
->related_resultset('workspace')
->search_related('user_workspace_roles', { user_id => $user_id })
->with_role($role)
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

my $build_rs = $self->related_resultset('build');

# this is Conch::DB::ResultSet::Build::user_has_role, unrolled
my $build_via_user_rs = $build_rs
->search_related('user_build_roles', { user_id => $user_id })
->with_role($role)
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

my $build_via_org_rs = $build_rs
->related_resultset('organization_build_roles')
->with_role($role)
->related_resultset('organization')
->search_related('user_organization_roles', { user_id => $user_id })
->related_resultset('user_account');
->related_resultset('user_account')
->columns(['id']);

return $ws_via_user_rs
->union_all($build_via_user_rs)
Expand Down

0 comments on commit 479d17a

Please sign in to comment.