Skip to content

Commit

Permalink
Merge pull request #78 from mlibrary/join-performance
Browse files Browse the repository at this point in the history
Improve query performance by adjusting join conditions
  • Loading branch information
botimer authored Jul 2, 2024
2 parents 7e5e80d + 4175fe6 commit 59c3b76
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lauth/app/repositories/grant_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def base_grants_for(username:, network:)
.where(grants[:dlpsDeleted].is("f"))
.left_join(users.name.dataset, userid: grants[:userid], dlpsDeleted: "f")
.left_join(institutions.name.dataset, uniqueIdentifier: grants[:inst], dlpsDeleted: "f")
.left_join(institution_memberships.name.dataset, inst: :uniqueIdentifier, dlpsDeleted: "f")
.left_join(institution_memberships.name.dataset, inst: :uniqueIdentifier, userid: username, dlpsDeleted: "f")
.left_join(Sequel.as(users.name.dataset, :inst_users), userid: :userid, dlpsDeleted: "f")
.left_join(groups.name.dataset, uniqueIdentifier: grants[:user_grp], dlpsDeleted: "f")
.left_join(group_memberships.name.dataset, user_grp: :uniqueIdentifier, dlpsDeleted: "f")
.left_join(group_memberships.name.dataset, user_grp: :uniqueIdentifier, userid: username, dlpsDeleted: "f")
.left_join(Sequel.as(users.name.dataset, :group_users), userid: :userid, dlpsDeleted: "f")
.left_join(Sequel.as(network, :smallest), inst: institutions[:uniqueIdentifier])
.where(
Expand All @@ -60,13 +60,11 @@ def base_grants_for(username:, network:)
),
Sequel.&(
Sequel.~(institutions[:uniqueIdentifier] => nil),
Sequel.~(Sequel[:inst_users][:userid] => nil),
{institution_memberships[:userid] => username}
Sequel.~(Sequel[:inst_users][:userid] => nil)
),
Sequel.&(
Sequel.~(groups[:uniqueIdentifier] => nil),
Sequel.~(Sequel[:group_users][:userid] => nil),
{group_memberships[:userid] => username}
Sequel.~(Sequel[:group_users][:userid] => nil)
),
Sequel.&(
Sequel.~(Sequel[:smallest][:inst] => nil),
Expand Down

0 comments on commit 59c3b76

Please sign in to comment.